| 98 |
- |
1 |
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
|
|
|
2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>5.53. Example - Stacked Squared Area Plot</title><link rel="stylesheet" type="text/css" href="phplotdoc.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><link rel="home" href="index.html" title="PHPlot Reference Manual" /><link rel="up" href="examples.html" title="Chapter 5. PHPlot Examples" /><link rel="prev" href="ex-squaredarea1.html" title="5.52. Example - Squared Area Plot" /><link rel="next" href="functions.html" title="Chapter 6. PHPlot Functions By Category" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.53. Example - Stacked Squared Area Plot</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-squaredarea1.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="functions.html">Next</a></td></tr></table><hr /></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ex-stackedsquaredarea1"></a>5.53. Example - Stacked Squared Area Plot</h2></div></div></div><p>
|
|
|
3 |
This is a stacked squared area plot (plot type
|
|
|
4 |
<a class="link" href="conc-plottypes.html#plottype-stackedsquaredarea" title="3.4.16. Plot Type: stackedsquaredarea (Stacked Squared Area Plot)">stackedsquaredarea</a>).
|
|
|
5 |
It is similar to the <a class="link" href="conc-plottypes.html#plottype-stackedarea" title="3.4.14. Plot Type: stackedarea (Stacked Area Plot)">stackedarea</a>)
|
|
|
6 |
plot, but the data lines are stepped as in the
|
|
|
7 |
<a class="link" href="conc-plottypes.html#plottype-squared" title="3.4.12. Plot Type: squared (Squared Plot)">squared</a>) plot.
|
|
|
8 |
</p><p>
|
|
|
9 |
Compare this image to the previous example,
|
|
|
10 |
<a class="xref" href="ex-squaredarea1.html" title="5.52. Example - Squared Area Plot">Section 5.52, “Example - Squared Area Plot”</a>,
|
|
|
11 |
which uses the same data but plots an unstacked (or non-cumulative) plot.
|
|
|
12 |
In this stacked plot, all the data sets are visible because they are
|
|
|
13 |
accumulated from first (Canada, light blue) to last (Nigeria, red).
|
|
|
14 |
Unlike in the unstacked plot, you cannot read the per-country values from
|
|
|
15 |
the Y axis scale. But also unlike the unstacked plot, you can visually
|
|
|
16 |
compare the relative amounts from each country, and also read the overall
|
|
|
17 |
total at the top of the plot.
|
|
|
18 |
</p><p>
|
|
|
19 |
In the script below, a copy of the last data row is appended to the data array.
|
|
|
20 |
This is usually necessary with the stackedsquaredarea plot if you want the
|
|
|
21 |
last data set to be visible. For an explanation, see description of the
|
|
|
22 |
<a class="link" href="conc-plottypes.html#plottype-stackedsquaredarea" title="3.4.16. Plot Type: stackedsquaredarea (Stacked Squared Area Plot)">stackedsquaredarea</a> plot type.
|
|
|
23 |
</p><p>
|
|
|
24 |
Note: Stacked Squared Area plots were added in PHPlot-6.2.0.
|
|
|
25 |
</p><div class="example"><a id="example-stackedsquaredarea1"></a><p class="title"><strong>Example 5.53. Stacked Squared Area Plot</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/stackedsquaredarea1.png" alt="Stacked Squared Area Plot" /></div></div><pre class="programlisting"><?php
|
|
|
26 |
# PHPlot Example: Stacked Squared Area plot
|
|
|
27 |
require_once 'phplot.php';
|
|
|
28 |
|
|
|
29 |
$title = "US Oil Imports by Country, Top 5\n"
|
|
|
30 |
. "Cumulative (stacked) Data";
|
|
|
31 |
|
|
|
32 |
$countries = array(
|
|
|
33 |
'Canada', 'Saudi Arabia', 'Mexico', 'Venezuela', 'Nigeria',
|
|
|
34 |
# -------- -------------- -------- ----------- ---------
|
|
|
35 |
);
|
|
|
36 |
$data = array(
|
|
|
37 |
array('2002', 1445, 1519, 1500, 1201, 589),
|
|
|
38 |
array('2003', 1549, 1726, 1569, 1183, 832),
|
|
|
39 |
array('2004', 1616, 1495, 1598, 1297, 1078),
|
|
|
40 |
array('2005', 1633, 1445, 1556, 1241, 1077),
|
|
|
41 |
array('2006', 1802, 1423, 1577, 1142, 1037),
|
|
|
42 |
array('2007', 1888, 1447, 1409, 1148, 1084),
|
|
|
43 |
array('2008', 1956, 1503, 1187, 1039, 922),
|
|
|
44 |
);
|
|
|
45 |
|
|
|
46 |
# Append a duplicate of the last row, without label, to make it visible.
|
|
|
47 |
$n_rows = count($data);
|
|
|
48 |
$data[$n_rows] = $data[$n_rows-1];
|
|
|
49 |
$data[$n_rows][0] = '';
|
|
|
50 |
|
|
|
51 |
$plot = new PHPlot(800, 600);
|
|
|
52 |
$plot->SetTitle($title);
|
|
|
53 |
$plot->SetYTitle('1000\'s of barrels per day');
|
|
|
54 |
$plot->SetDataType('text-data');
|
|
|
55 |
$plot->SetDataValues($data);
|
|
|
56 |
$plot->SetPlotType('stackedsquaredarea');
|
|
|
57 |
$plot->SetXTickPos('none');
|
|
|
58 |
$plot->SetLineStyles('solid');
|
|
|
59 |
$plot->SetYTickIncrement(250);
|
|
|
60 |
$plot->SetLegend($countries);
|
|
|
61 |
# Make room for the legend to the left of the plot:
|
|
|
62 |
$plot->SetMarginsPixels(200);
|
|
|
63 |
# Move the legend to the left:
|
|
|
64 |
$plot->SetLegendPixels(10, 10);
|
|
|
65 |
# Flip the legend order for stacked plots:
|
|
|
66 |
$plot->SetLegendReverse(True);
|
|
|
67 |
# To improve presentation in the manual:
|
|
|
68 |
$plot->SetImageBorderType('plain');
|
|
|
69 |
$plot->DrawGraph();
|
|
|
70 |
</pre></div></div><br class="example-break" /></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ex-squaredarea1.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="examples.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.52. Example - Squared Area Plot </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 6. PHPlot Functions By Category</td></tr></table></div></body></html>
|