Contents Previous Next

6.4 Error plots

Error plots are used to visually indicate uncertainty in data points. This is done by for each X value by giving both a minimum and a maximum Y-value.

Before you can use error plots you must remember to include the file "jpgraph_error.php" in your script.

The following example illustrates a simple error bar. We will have 5 points, so we need 10 Y-values. We also would like the error bars to be red and 2 pixels wide. All this is accomplished by creating an ErrorPlot() in much the same way as, for example, a normal line plot. Doing this would now give the example shown below.



Figure 1: A simple error bar [src]

You might notice that there is one displeasing aesthetical quality of this graph. The X-scale is just wide enough to just accompany the number of error bars and hence the first bar is drawn on the Y-axis and the and last bar just at the edge of the plot area. To adjust this you might call the SetCenter() method which will adjust the X-scale so it does not use the full width of the X-axis.

The following example illustrates the use of this feature by applying this technique to the previous example



Figure 2: Adjusting the X-scale not to use the full width of the X-axis. [src]

6.4.1 Using line error plots

A line error plot is an error plot with the addition that a line is drawn between the average value of each error pair. You use this type of plot the exact same way you would use an error plot. The only change is that you must instantiated an ErrorLinePlot() instead and make sure you have included the "jpgraph_line.php" since the line error plot makes use of the line plot class to stroke the line.

To control the various properties of the line drawn the "line" property of the error line plot may be accessed. So, for example, if you want the line to be 2 pixels wide and blue you would have to add the following two lines
 

$elplot->line->SetWeight(2);
$elplot->line->SetColor("blue");

to generate the graph as shown below



Figure 3: Linear error plot [src]

You may of course add legends to none, one or both of the line types in the above graph. So for example if we wanted the legend "Min/Max" for the red error bars and a legend "Average" for the blue line you would have to add the lines
 

$errplot->SetLegend("Min/Max");
$errplot->line->SetLegend("Average");

The resulting graph will now look like (note that we are using the default placement of the legend box)



Figure 4: Addding a legend box to the line error plot. [src]


Contents Previous Next