62 lines
9.5 KiB
HTML
62 lines
9.5 KiB
HTML
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Combining several different plot types in the same graph</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">Combining several different plot types in the same graph</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="Combining several different plot types in the same graph"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2563579"></a>Combining several different plot types in the same graph</h2></div></div></div>
|
||
|
||
<p>It is perfectly legal to add several different plot types to the same graph. For
|
||
example to mix a line plot with a filled area plot. The different plots will be
|
||
stroked to the graph in the order they are added. This means that the plot (data
|
||
series) that should always be visible should be added last. In the example with the
|
||
filled area and a line the line should probably be added last since it otherwise
|
||
most likely will be overwritten by the filled area plot.</p>
|
||
<p>In <a class="xref" href="ch15s07.html#fig.example16.1" title="Figure 15.84. Mixing a line and area plot in the same graph (example16.1.php)">Figure 15.84. Mixing a line and area plot in the same graph <code class="uri"><a class="uri" href="example_src/example16.1.html" target="_top">(<code class="filename">example16.1.php</code>)</a></code> </a> a basic example is shown where we have
|
||
combined a line plot with an area plot.</p>
|
||
<p>
|
||
</p><div class="figure"><a name="fig.example16.1"></a><p class="title"><b>Figure 15.84. Mixing a line and area plot in the same graph <code class="uri"><a class="uri" href="example_src/example16.1.html" target="_top">(<code class="filename">example16.1.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example16.1.png" alt="Mixing a line and area plot in the same graph (example16.1.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
<p>As can be seen from looking at the source to the example in <a class="xref" href="ch15s07.html#fig.example16.1" title="Figure 15.84. Mixing a line and area plot in the same graph (example16.1.php)">Figure 15.84. Mixing a line and area plot in the same graph <code class="uri"><a class="uri" href="example_src/example16.1.html" target="_top">(<code class="filename">example16.1.php</code>)</a></code> </a> there is nothing special in doing this other
|
||
then to remember to include all necessary header files. So to add and mix scatter,
|
||
line, error and stock graphs are pretty straightforward.</p>
|
||
<p>However, when it comes to mixing bar plots and lines (or area plot) there is a
|
||
complication. By default bar plots are centered <span class="italic">between</span> the tick marks since this is the standard way of displaying
|
||
bar graphs since they normally have no specific x-scale. The bars are just in an
|
||
ordered sequence.</p>
|
||
<p>Let's just see what happens if we create a basic bar with a text scale on the
|
||
x-axis and then also add a line plot to the same graph.</p>
|
||
<p>
|
||
</p><div class="figure"><a name="fig.example16.3"></a><p class="title"><b>Figure 15.85. Mixing a line and bar plot in the same graph <code class="uri"><a class="uri" href="example_src/example16.3.html" target="_top">(<code class="filename">example16.3.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example16.3.png" alt="Mixing a line and bar plot in the same graph (example16.3.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
<p>As can be seen from <a class="xref" href="ch15s07.html#fig.example16.3" title="Figure 15.85. Mixing a line and bar plot in the same graph (example16.3.php)">Figure 15.85. Mixing a line and bar plot in the same graph <code class="uri"><a class="uri" href="example_src/example16.3.html" target="_top">(<code class="filename">example16.3.php</code>)</a></code> </a> the line is adjusted so
|
||
that each data point on the line coincides with the left edge of the barplot and the
|
||
bars are still positoined in the middle of the tick marks as could be expected. This
|
||
is the default behavior when combining a barplot with one of the other linear
|
||
plots.</p>
|
||
<p>If we instead wanted the line to be centered in the barplot (when using a text
|
||
scale) we would have to tell the line plot to position itself in the middle of the
|
||
bars with the method</p>
|
||
<p>
|
||
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||
<p><code class="code">LinePlot::SetBarCenter()</code></p>
|
||
</li></ul></div><p>
|
||
</p>
|
||
<p>Using this method would then give the result shown in <a class="xref" href="ch15s07.html#fig.linebarcentex1" title="Figure 15.86. Centering the line plot in the middle of the bar (linebarcentex1.php)">Figure 15.86. Centering the line plot in the middle of the bar <code class="uri"><a class="uri" href="example_src/linebarcentex1.html" target="_top">(<code class="filename">linebarcentex1.php</code>)</a></code> </a> below</p>
|
||
<p>
|
||
</p><div class="figure"><a name="fig.linebarcentex1"></a><p class="title"><b>Figure 15.86. Centering the line plot in the middle of the bar <code class="uri"><a class="uri" href="example_src/linebarcentex1.html" target="_top">(<code class="filename">linebarcentex1.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/linebarcentex1.png" alt="Centering the line plot in the middle of the bar (linebarcentex1.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
<p>Please note that the above discussion is only valid when using a text scale. if we
|
||
instead would use (for example) an integer scale then both the bar and the line
|
||
would be positioned at the exact scale values (i.e. both bars and lines would be
|
||
left aligned) as can be seen in <a class="xref" href="ch15s07.html#fig.example16.4" title="Figure 15.87. Mixing bar and line using an integer x-scale (example16.4.php)">Figure 15.87. Mixing bar and line using an integer x-scale <code class="uri"><a class="uri" href="example_src/example16.4.html" target="_top">(<code class="filename">example16.4.php</code>)</a></code> </a></p>
|
||
<p>
|
||
</p><div class="figure"><a name="fig.example16.4"></a><p class="title"><b>Figure 15.87. Mixing bar and line using an integer x-scale <code class="uri"><a class="uri" href="example_src/example16.4.html" target="_top">(<code class="filename">example16.4.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/example16.4.png" alt="Mixing bar and line using an integer x-scale (example16.4.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
<p>
|
||
</p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
|
||
<p>As can be seen in <a class="xref" href="ch15s07.html#fig.example16.4" title="Figure 15.87. Mixing bar and line using an integer x-scale (example16.4.php)">Figure 15.87. Mixing bar and line using an integer x-scale <code class="uri"><a class="uri" href="example_src/example16.4.html" target="_top">(<code class="filename">example16.4.php</code>)</a></code> </a> it is possible to
|
||
manually set the scale labels even if we use a linear scale like an integer
|
||
scale. We only have to keep in mind that we ned to supply labels for all the
|
||
scale labels and not just the one that are shown in case the scale is fro
|
||
example only displaying a label on every second tick.</p>
|
||
</div><p>
|
||
</p>
|
||
<p>An example on how to combine a scatter plot and a line plot is shown in <a class="xref" href="ch18.html#sec.linear-regression-analysis" title="Linear regression analysis">Linear regression analysis</a> where a linear regression
|
||
analysis is done.</p>
|
||
</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>
|