2.4. Different Size Images and Titles
Prev | Chapter 2. Getting Started with PHPlot | Next

## 2.4. Different Size Images and Titles

Let's say we want our plot to be bigger, 800 pixels wide and 600 pixels high. So instead of having the line

      $plot = new PHPlot;

We replace it with

      $plot = new PHPlot(800,600);

and you have specified the size in pixels of the image to be created.

A couple of things to note:

- The default is not to use TrueType fonts.

- Since there was only one graph on the image, we didn't have to use PrintImage. DrawGraph took care of it for us.

- We did not specify the data type. If you do not specify the data type, PHPlot assumes `text-data`.

- We did not specify the file type (GIF, PNG, JPEG, ...). PHPlot 5.0 (and newer) makes PNG images by default.

- The data is passed in as an array of arrays. This may seem awkward now, but as we add functionality this will be beneficial.

OK, now we're ready to add some customization to the plot. Let's change the size, the title and the X/Y axis labels. All we need to do is use additional methods of the `$plot` object before printing the image. Here is the complete result:

    <?php
    //Include the code
    require_once 'phplot.php';

    //create a PHPlot object with 800x600 pixel image
    $plot = new PHPlot(800,600);

    //Define some data
    $example_data = array(
         array('a',3),
         array('b',5),
         array('c',7),
         array('d',8),
         array('e',2),
         array('f',6),
         array('g',7)
    );
    $plot->SetDataValues($example_data);

    //Set titles
    $plot->SetTitle("A Simple Plot\nMade with PHPlot");
    $plot->SetXTitle('X Data');
    $plot->SetYTitle('Y Data');

    //Turn off X axis ticks and labels because they get in the way:
    $plot->SetXTickLabelPos('none');
    $plot->SetXTickPos('none');

    //Draw it
    $plot->DrawGraph();

And that's it! What we get is the following graph:

Note that the newline character "\n" separates multiple lines in titles, and you must use double quotes around the title string for PHP to recognize the newline.

Prev | Up | Next
2.3. A Simple Graph | Home | 2.5. Multiple Lines Per Graph