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.18. Example - Two Plots on One Image</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-thinbarline2.html" title="5.17. Example - Thin Bar Line Plot, Wider Lines" /><link rel="next" href="ex-bars4.html" title="5.19. Example - Bar Chart with Data Value Labels" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.18. Example - Two Plots on One Image</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-thinbarline2.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-bars4.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-twoplot1"></a>5.18. Example - Two Plots on One Image</h2></div></div></div><p>
|
|
|
3 |
This example shows multiple plots tiled on a single image.
|
|
|
4 |
To place multiple plots on an image, first disable automatic output with
|
|
|
5 |
<a class="xref" href="SetPrintImage.html" title="SetPrintImage"><span class="refentrytitle">SetPrintImage</span></a>(False). Then define each plot area using
|
|
|
6 |
<a class="xref" href="SetPlotAreaPixels.html" title="SetPlotAreaPixels"><span class="refentrytitle">SetPlotAreaPixels</span></a> and create the plot.
|
|
|
7 |
Finish each plot with <a class="xref" href="DrawGraph.html" title="DrawGraph"><span class="refentrytitle">DrawGraph</span></a>.
|
|
|
8 |
At the end, <a class="xref" href="PrintImage.html" title="PrintImage"><span class="refentrytitle">PrintImage</span></a> outputs the image containing all
|
|
|
9 |
of the plots.
|
|
|
10 |
</p><p>
|
|
|
11 |
See <a class="xref" href="adv-multiplot.html" title="4.8. Multiple Plots Per Image">Section 4.8, “Multiple Plots Per Image”</a> for more information.
|
|
|
12 |
</p><div class="example"><a id="example-twoplot1"></a><p class="title"><strong>Example 5.18. Two Plots on One Image</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/twoplot1.png" alt="Two Plots on One Image Example" /></div></div><pre class="programlisting"><?php
|
|
|
13 |
# PHPlot Example: Two plots on one image
|
|
|
14 |
require_once 'phplot.php';
|
|
|
15 |
|
|
|
16 |
$data1 = array( # Data array for top plot: Imports
|
|
|
17 |
array('1981', 5996), array('1982', 5113), array('1983', 5051),
|
|
|
18 |
array('1984', 5437), array('1985', 5067), array('1986', 6224),
|
|
|
19 |
array('1987', 6678), array('1988', 7402), array('1989', 8061),
|
|
|
20 |
array('1990', 8018), array('1991', 7627), array('1992', 7888),
|
|
|
21 |
array('1993', 8620), array('1994', 8996), array('1995', 8835),
|
|
|
22 |
array('1996', 9478), array('1997', 10162), array('1998', 10708),
|
|
|
23 |
array('1999', 10852), array('2000', 11459),
|
|
|
24 |
);
|
|
|
25 |
$data2 = array( # Data array for bottom plot: Exports
|
|
|
26 |
array('1981', 595), array('1982', 815), array('1983', 739),
|
|
|
27 |
array('1984', 722), array('1985', 781), array('1986', 785),
|
|
|
28 |
array('1987', 764), array('1988', 815), array('1989', 859),
|
|
|
29 |
array('1990', 857), array('1991', 1001), array('1992', 950),
|
|
|
30 |
array('1993', 1003), array('1994', 942), array('1995', 949),
|
|
|
31 |
array('1996', 981), array('1997', 1003), array('1998', 945),
|
|
|
32 |
array('1999', 940), array('2000', 1040),
|
|
|
33 |
);
|
|
|
34 |
|
|
|
35 |
$plot = new PHPlot(800,600);
|
|
|
36 |
$plot->SetImageBorderType('plain');
|
|
|
37 |
|
|
|
38 |
# Disable auto-output:
|
|
|
39 |
$plot->SetPrintImage(0);
|
|
|
40 |
|
|
|
41 |
# There is only one title: it is outside both plot areas.
|
|
|
42 |
$plot->SetTitle('US Petroleum Import/Export');
|
|
|
43 |
|
|
|
44 |
# Set up area for first plot:
|
|
|
45 |
$plot->SetPlotAreaPixels(80, 40, 740, 350);
|
|
|
46 |
|
|
|
47 |
# Do the first plot:
|
|
|
48 |
$plot->SetDataType('text-data');
|
|
|
49 |
$plot->SetDataValues($data1);
|
|
|
50 |
$plot->SetPlotAreaWorld(NULL, 0, NULL, 13000);
|
|
|
51 |
$plot->SetDataColors(array('blue'));
|
|
|
52 |
$plot->SetXTickLabelPos('none');
|
|
|
53 |
$plot->SetXTickPos('none');
|
|
|
54 |
$plot->SetYTickIncrement(1000);
|
|
|
55 |
$plot->SetYTitle("IMPORTS\n1000 barrels/day");
|
|
|
56 |
|
|
|
57 |
$plot->SetPlotType('bars');
|
|
|
58 |
$plot->DrawGraph();
|
|
|
59 |
|
|
|
60 |
# Set up area for second plot:
|
|
|
61 |
$plot->SetPlotAreaPixels(80, 400, 740, 550);
|
|
|
62 |
|
|
|
63 |
# Do the second plot:
|
|
|
64 |
$plot->SetDataType('text-data');
|
|
|
65 |
$plot->SetDataValues($data2);
|
|
|
66 |
$plot->SetPlotAreaWorld(NULL, 0, NULL, 1300);
|
|
|
67 |
$plot->SetDataColors(array('green'));
|
|
|
68 |
$plot->SetXTickLabelPos('none');
|
|
|
69 |
$plot->SetXTickPos('none');
|
|
|
70 |
$plot->SetYTickIncrement(200);
|
|
|
71 |
$plot->SetYTitle("EXPORTS\n1000 barrels/day");
|
|
|
72 |
|
|
|
73 |
$plot->SetPlotType('bars');
|
|
|
74 |
$plot->DrawGraph();
|
|
|
75 |
|
|
|
76 |
# Output the image now:
|
|
|
77 |
$plot->PrintImage();
|
|
|
78 |
</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-thinbarline2.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="ex-bars4.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.17. Example - Thin Bar Line Plot, Wider Lines </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.19. Example - Bar Chart with Data Value Labels</td></tr></table></div></body></html>
|