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.34. Example - Overlaying Plots</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-linepoints2.html" title="5.33. Example - Linepoints Plot with Data Value Labels" /><link rel="next" href="ex-legendshape.html" title="5.35. Example - Legend with Shape Markers" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.34. Example - Overlaying Plots</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-linepoints2.html">Prev</a> </td><thwidth="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-legendshape.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-outbreak"></a>5.34. Example - Overlaying Plots</h2></div></div></div><p>This example shows overlay plots, where multiple plots are drawn at the sameposition on the same image. In this case, one plot contains a stacked barplot, and the second is a linepoints plot. The two plots also havedifferent Y axis scales.</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-outbreak"></a><p class="title"><strong>Example 5.34. Overlaying Plots</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/outbreak.png" alt="Overlay Plot Example" /></div></div><pre class="programlisting"><?php# PHPlot Example: Plot Overlay (lines and stackedbars)require_once 'phplot.php';$title = '2009 Outbreak, Positive Tests';# Note: Graph is based on the real thing, but the data is invented.# Data for plot #1: stackedbars:$y_title1 = 'Number of positive tests';$data1 = array(array('1/09', 200, 200, 300),array('2/09', 300, 100, 700),array('3/09', 400, 200, 800),array('4/09', 500, 300, 1200),array('5/09', 400, 400, 2500),array('6/09', 500, 600, 3600),array('7/09', 400, 1200, 3300),array('8/09', 300, 1500, 2500),array('9/09', 200, 1900, 800),array('10/09', 100, 2000, 200),array('11/09', 100, 2500, 100),array('12/09', 100, 2700, 200),);$legend1 = array('Strain A', 'Strain B', 'Strain C');# Data for plot #2: linepoints:$y_title2 = 'Percent Positive';$data2 = array(array('1/09', 5),array('2/09', 10),array('3/09', 15),array('4/09', 30),array('5/09', 40),array('6/09', 45),array('7/09', 47),array('8/09', 35),array('9/09', 25),array('10/09', 20),array('11/09', 25),array('12/09', 30),);$legend2 = array('% positive');$plot = new PHPlot(800, 600);$plot->SetImageBorderType('plain'); // For presentation in the manual$plot->SetPrintImage(False); // Defer output until the end$plot->SetTitle($title);$plot->SetPlotBgColor('gray');$plot->SetLightGridColor('black'); // So grid stands out from background# Plot 1$plot->SetDrawPlotAreaBackground(True);$plot->SetPlotType('stackedbars');$plot->SetDataType('text-data');$plot->SetDataValues($data1);$plot->SetYTitle($y_title1);# Set and position legend #1:$plot->SetLegend($legend1);$plot->SetLegendPixels(5, 30);# Set margins to leave room for plot 2 Y title on the right.$plot->SetMarginsPixels(120, 120);# Specify Y range of these data sets:$plot->SetPlotAreaWorld(NULL, 0, NULL, 5000);$plot->SetYTickIncrement(500);$plot->SetXTickLabelPos('none');$plot->SetXTickPos('none');# Format Y tick labels as integers, with thousands separator:$plot->SetYLabelType('data', 0);$plot->DrawGraph();# Plot 2$plot->SetDrawPlotAreaBackground(False); // Cancel background$plot->SetDrawYGrid(False); // Cancel grid, already drawn$plot->SetPlotType('linepoints');$plot->SetDataValues($data2);# Set Y title for plot #2 and position it on the right side:$plot->SetYTitle($y_title2, 'plotright');# Set and position legend #2:$plot->SetLegend($legend2);$plot->SetLegendPixels(690, 30);# Specify Y range of this data set:$plot->SetPlotAreaWorld(NULL, 0, NULL, 50);$plot->SetYTickIncrement(10);$plot->SetYTickPos('plotright');$plot->SetYTickLabelPos('plotright');$plot->SetDataColors('black');# Format Y tick labels as integers with trailing percent sign:$plot->SetYLabelType('data', 0, '', '%');$plot->DrawGraph();# Now output the graph with both plots:$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-linepoints2.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-legendshape.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.33. Example - Linepoints Plot with Data Value Labels </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.35. Example - Legend with Shape Markers</td></tr></table></div></body></html>