ch15s03.html
9.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Error plot graphs</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="ch15.html" title="Chapter 15. Different types of linear (cartesian) graph types"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Error plot graphs</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Chapter 15. Different types of linear (cartesian) graph types</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="sect1" title="Error plot graphs"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec1.creating-error-graphs"></a>Error plot graphs</h2></div></div></div>
<p>Error plots are used to visually indicate uncertainty in data points. This is done
by specifying both a min and and max value for each data point.</p>
<p>Before error plots can be used the module "<code class="filename">jpgraph_error.php</code>"
must be included.</p>
<p>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 instance of the <code class="code">ErrorPlot</code> class in
much the same way as, for example, a normal line plot.</p>
<p>
</p><div class="figure"><a name="fig.example13"></a><p class="title"><b>Figure 15.58. A basic error plot <code class="uri"><a class="uri" href="example_src/example13.html" target="_top">(<code class="filename">example13.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example13.png" alt="A basic error plot (example13.php)"></span> </div></div><p><br class="figure-break">
</p>
<p>There is one displeasing esthetic 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. </p>
<p>To adjust this we can use the method <code class="code">ErrorPlot::SetCenter()</code> which
will adjust the x-scale so it does not use the full width of the X-axis.</p>
<p>
</p><div class="figure"><a name="fig.example14"></a><p class="title"><b>Figure 15.59. Making use of SetCenter() with error plots <code class="uri"><a class="uri" href="example_src/example14.html" target="_top">(<code class="filename">example14.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example14.png" alt="Making use of SetCenter() with error plots (example14.php)"></span> </div></div><p><br class="figure-break">
</p>
<p></p>
<div class="sect2" title="Line error plots"><div class="titlepage"><div><div><h3 class="title"><a name="id2560625"></a>Line error plots</h3></div></div></div>
<p>A variant of the error plot graph is to use an <code class="code">LineErrorPlot</code>
instead. This is almost the same as the <code class="code">ErrorPlot</code> but with the
added feature that each data point also has an middle value which a line is
drawn through. This can be thought of as a line plot combined with an error
plot.</p>
<p>Since this also uses a line the module "<code class="filename">jpgraph_line.ph</code>p"
must be included in addition to the error module.</p>
<p>To control the various properties of the line drawn the "line" property of the
error line plot may be accessed. So, for example, to set the line to have weight
of 2 pixels wide and with a blue color the following two lines are needed</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
</span><span class="hl-var">$elplot</span><span class="hl-code">-></span><span class="hl-identifier">line</span><span class="hl-code">-></span><span class="hl-identifier">SetWeight</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-number">2</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$elplot</span><span class="hl-code">-></span><span class="hl-identifier">line</span><span class="hl-code">-></span><span class="hl-identifier">SetColor</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">blue</span><span class="hl-quotes">'</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div><p>
</p>
<p>An example of this is shown in <a class="xref" href="ch15s03.html#fig.example15" title="Figure 15.60. A basic Line error plot (example15.php)">Figure 15.60. A basic Line error plot <code class="uri"><a class="uri" href="example_src/example15.html" target="_top">(<code class="filename">example15.php</code>)</a></code> </a>. We could
now also add a legend to none, one or both of the line types(the plain line
and/or the error bar). So for example if we wanted the legend "Min/Max" for the
red error bars and a legend "Average" for the blue line the following lines
should be added</p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
</span><span class="hl-var">$errplot</span><span class="hl-code">-></span><span class="hl-identifier">SetLegend</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">Min/Max</span><span class="hl-quotes">'</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$errplot</span><span class="hl-code">-></span><span class="hl-identifier">line</span><span class="hl-code">-></span><span class="hl-identifier">SetLegend</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">Average</span><span class="hl-quotes">'</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div><p>
</p>
<p>The result is shown in <a class="xref" href="ch15s03.html#fig.example16" title="Figure 15.61. A line error plot with a legend (example16.php)">Figure 15.61. A line error plot with a legend <code class="uri"><a class="uri" href="example_src/example16.html" target="_top">(<code class="filename">example16.php</code>)</a></code> </a></p>
<p>
</p><div class="informaltable">
<table border="0"><colgroup><col class="c1"><col class="c2"></colgroup><tbody><tr><td>
<div class="figure"><a name="fig.example15"></a><p class="title"><b>Figure 15.60. A basic Line error plot <code class="uri"><a class="uri" href="example_src/example15.html" target="_top">(<code class="filename">example15.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example15.png" alt="A basic Line error plot (example15.php)"></span> </div></div><br class="figure-break">
</td><td>
<div class="figure"><a name="fig.example16"></a><p class="title"><b>Figure 15.61. A line error plot with a legend <code class="uri"><a class="uri" href="example_src/example16.html" target="_top">(<code class="filename">example16.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example16.png" alt="A line error plot with a legend (example16.php)"></span> </div></div><br class="figure-break">
</td></tr></tbody></table>
</div><p>
</p>
</div>
</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"><a accesskey="u" href="ch15.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>