This is a stacked squared area plot (plot type stackedsquaredarea). It is similar to the stackedarea) plot, but the data lines are stepped as in the squared) plot.
Compare this image to the previous example, Section 5.52, “Example - Squared Area Plot”, which uses the same data but plots an unstacked (or non-cumulative) plot. In this stacked plot, all the data sets are visible because they are accumulated from first (Canada, light blue) to last (Nigeria, red). Unlike in the unstacked plot, you cannot read the per-country values from the Y axis scale. But also unlike the unstacked plot, you can visually compare the relative amounts from each country, and also read the overall total at the top of the plot.
In the script below, a copy of the last data row is appended to the data array. This is usually necessary with the stackedsquaredarea plot if you want the last data set to be visible. For an explanation, see description of the stackedsquaredarea plot type.
Note: Stacked Squared Area plots were added in PHPlot-6.2.0.
Example 5.53. Stacked Squared Area Plot
<?php # PHPlot Example: Stacked Squared Area plot require_once 'phplot.php'; $title = "US Oil Imports by Country, Top 5\n" . "Cumulative (stacked) Data"; $countries = array( 'Canada', 'Saudi Arabia', 'Mexico', 'Venezuela', 'Nigeria', # -------- -------------- -------- ----------- --------- ); $data = array( array('2002', 1445, 1519, 1500, 1201, 589), array('2003', 1549, 1726, 1569, 1183, 832), array('2004', 1616, 1495, 1598, 1297, 1078), array('2005', 1633, 1445, 1556, 1241, 1077), array('2006', 1802, 1423, 1577, 1142, 1037), array('2007', 1888, 1447, 1409, 1148, 1084), array('2008', 1956, 1503, 1187, 1039, 922), ); # Append a duplicate of the last row, without label, to make it visible. $n_rows = count($data); $data[$n_rows] = $data[$n_rows-1]; $data[$n_rows][0] = ''; $plot = new PHPlot(800, 600); $plot->SetTitle($title); $plot->SetYTitle('1000\'s of barrels per day'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); $plot->SetPlotType('stackedsquaredarea'); $plot->SetXTickPos('none'); $plot->SetLineStyles('solid'); $plot->SetYTickIncrement(250); $plot->SetLegend($countries); # Make room for the legend to the left of the plot: $plot->SetMarginsPixels(200); # Move the legend to the left: $plot->SetLegendPixels(10, 10); # Flip the legend order for stacked plots: $plot->SetLegendReverse(True); # To improve presentation in the manual: $plot->SetImageBorderType('plain'); $plot->DrawGraph();
This version of the manual was produced for the
PHPlot Sourceforge project web service site, which requires the logo on each
page.
To download a logo-free copy of the manual, see the
PHPlot project downloads
area.