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.40. Example - Bubbles 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-encodeimage.html" title="5.39. Example - Embedding Image with EncodeImage" /><link rel="next" href="ex-pielabeltype.html" title="5.41. Example - Pie Chart Label Types" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.40. Example - Bubbles Plot</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-encodeimage.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-pielabeltype.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-bubbles1"></a>5.40. Example - Bubbles Plot</h2></div></div></div><p>This example shows a <a class="link" href="conc-plottypes.html#plottype-bubbles" title="3.4.4. Plot Type: bubbles (Bubble Plot)">bubbles plot</a>.A data array for a bubbles plot uses the<a class="link" href="conc-datatypes.html#data-data-xyz">data-data-xyz</a> data type, in which threecoordinate values specify each point: X and Y are the position on the plot,and Z maps to the bubble diameter.</p><p>In this example, X is the flavor, Y is the age group, and Z represents thepercentage of participants who liked that flavor.Note that there are two missing points in the Y=1 row. No bubbles aredrawn at X=3,Y=1 or X=5,Y=1.Presumably, no-one under 12 would try the pear or kiwi flavors, so there areno valid data points there. This is different from a value Z=0, whichwould be plotted with a bubble of the smallest size.</p><p>This plot type was added in PHPlot-5.5.0.</p><p>This example also shows the use of custom Y labels. A function<code class="function">get_label()</code> is defined to map the Y tick valueinto a string from an array of strings. This method allows the displayof arbitrary labels along the Y axis.See <a class="xref" href="SetYLabelType.html" title="SetYLabelType"><span class="refentrytitle">SetYLabelType</span></a> for details.</p><div class="example"><a id="example-bubbles1"></a><p class="title"><strong>Example 5.40. Bubbles Plot</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/bubbles1.png" alt="Bubbles Plot Example" /></div></div><pre class="programlisting"><?php# PHPlot Example - Bubble Plotrequire_once 'phplot.php';# Array of custom labels for the Y axis. See the get_label callback.$y_labels = array("", "Age\n12 and under", "Age 13-17", "Age 18-29","Age 30-39", "Age 40-54", "Age\n55 and older");# Return the string for a Y label:function get_label($value, $labels){if (isset($labels[(int)$value])) return $labels[(int)$value];return $value;}# <=12 13-17 17-28 30-39 40-54 >=55$data = array(array('Cherry', 1, 1, 2, 2, 4, 3, 3, 4, 3, 5, 5, 6, 6),array('Apple', 2, 1, 9, 2, 7, 3, 4, 4, 7, 5, 3, 6, 7),array('Pear', 3, '', 2, 2, 2, 3, 3, 4, 4, 5, 3, 6, 2),array('Grape', 4, 1, 8, 2, 5, 3, 5, 4, 6, 5, 3, 6, 4),array('Kiwi', 5, '', 0, 2, 3, 3, 4, 4, 4, 5, 5, 6, 2),array('Banana', 6, 1, 5, 2, 4, 3, 6, 4, 3, 5, 3, 6, 4),);$plot = new PHPlot(600, 600);$plot->SetTitle("Flavor Preference By Age Group");$plot->SetDataType('data-data-xyz');$plot->SetDataValues($data);$plot->SetPlotType('bubbles');$plot->SetDataColors('yellow'); // Use same color for all data sets$plot->SetDrawPlotAreaBackground(True);$plot->SetPlotBgColor('plum');$plot->SetLightGridColor('red'); // Change grid color to make it visible$plot->SetImageBorderType('plain');$plot->SetPlotBorderType('full');$plot->SetXTickIncrement(1); // For grid line spacing$plot->SetYTickIncrement(1);$plot->SetPlotAreaWorld(0, 0, 6.5, 6.5);# Establish the handler for the Y label text:$plot->SetYLabelType('custom', 'get_label', $y_labels);$plot->SetXTickPos('both'); // Tick marks on both sides$plot->SetYTickPos('both'); // Tick marks on top and bottom too$plot->SetXDataLabelPos('both'); // X axis data labels top and bottom$plot->SetYTickLabelPos('both'); // Y axis labels left and right$plot->SetDrawXGrid(True);$plot->DrawGraph();</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-encodeimage.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-pielabeltype.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.39. Example - Embedding Image with EncodeImage </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.41. Example - Pie Chart Label Types</td></tr></table></div></body></html>