Blame | Last modification | View Log | RSS feed
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><!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>This example shows multiple plots tiled on a single image.To place multiple plots on an image, first disable automatic output with<a class="xref" href="SetPrintImage.html" title="SetPrintImage"><span class="refentrytitle">SetPrintImage</span></a>(False). Then define each plot area using<a class="xref" href="SetPlotAreaPixels.html" title="SetPlotAreaPixels"><span class="refentrytitle">SetPlotAreaPixels</span></a> and create the plot.Finish each plot with <a class="xref" href="DrawGraph.html" title="DrawGraph"><span class="refentrytitle">DrawGraph</span></a>.At the end, <a class="xref" href="PrintImage.html" title="PrintImage"><span class="refentrytitle">PrintImage</span></a> outputs the image containing allof the plots.</p><p>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.</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# PHPlot Example: Two plots on one imagerequire_once 'phplot.php';$data1 = array( # Data array for top plot: Importsarray('1981', 5996), array('1982', 5113), array('1983', 5051),array('1984', 5437), array('1985', 5067), array('1986', 6224),array('1987', 6678), array('1988', 7402), array('1989', 8061),array('1990', 8018), array('1991', 7627), array('1992', 7888),array('1993', 8620), array('1994', 8996), array('1995', 8835),array('1996', 9478), array('1997', 10162), array('1998', 10708),array('1999', 10852), array('2000', 11459),);$data2 = array( # Data array for bottom plot: Exportsarray('1981', 595), array('1982', 815), array('1983', 739),array('1984', 722), array('1985', 781), array('1986', 785),array('1987', 764), array('1988', 815), array('1989', 859),array('1990', 857), array('1991', 1001), array('1992', 950),array('1993', 1003), array('1994', 942), array('1995', 949),array('1996', 981), array('1997', 1003), array('1998', 945),array('1999', 940), array('2000', 1040),);$plot = new PHPlot(800,600);$plot->SetImageBorderType('plain');# Disable auto-output:$plot->SetPrintImage(0);# There is only one title: it is outside both plot areas.$plot->SetTitle('US Petroleum Import/Export');# Set up area for first plot:$plot->SetPlotAreaPixels(80, 40, 740, 350);# Do the first plot:$plot->SetDataType('text-data');$plot->SetDataValues($data1);$plot->SetPlotAreaWorld(NULL, 0, NULL, 13000);$plot->SetDataColors(array('blue'));$plot->SetXTickLabelPos('none');$plot->SetXTickPos('none');$plot->SetYTickIncrement(1000);$plot->SetYTitle("IMPORTS\n1000 barrels/day");$plot->SetPlotType('bars');$plot->DrawGraph();# Set up area for second plot:$plot->SetPlotAreaPixels(80, 400, 740, 550);# Do the second plot:$plot->SetDataType('text-data');$plot->SetDataValues($data2);$plot->SetPlotAreaWorld(NULL, 0, NULL, 1300);$plot->SetDataColors(array('green'));$plot->SetXTickLabelPos('none');$plot->SetXTickPos('none');$plot->SetYTickIncrement(200);$plot->SetYTitle("EXPORTS\n1000 barrels/day");$plot->SetPlotType('bars');$plot->DrawGraph();# Output the image now:$plot->PrintImage();</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>