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.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>
|
|
|
3 |
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>.
|
|
|
4 |
A data array for a bubbles plot uses the
|
|
|
5 |
<a class="link" href="conc-datatypes.html#data-data-xyz">data-data-xyz</a> data type, in which three
|
|
|
6 |
coordinate values specify each point: X and Y are the position on the plot,
|
|
|
7 |
and Z maps to the bubble diameter.
|
|
|
8 |
</p><p>
|
|
|
9 |
In this example, X is the flavor, Y is the age group, and Z represents the
|
|
|
10 |
percentage of participants who liked that flavor.
|
|
|
11 |
Note that there are two missing points in the Y=1 row. No bubbles are
|
|
|
12 |
drawn at X=3,Y=1 or X=5,Y=1.
|
|
|
13 |
Presumably, no-one under 12 would try the pear or kiwi flavors, so there are
|
|
|
14 |
no valid data points there. This is different from a value Z=0, which
|
|
|
15 |
would be plotted with a bubble of the smallest size.
|
|
|
16 |
</p><p>
|
|
|
17 |
This plot type was added in PHPlot-5.5.0.
|
|
|
18 |
</p><p>
|
|
|
19 |
This example also shows the use of custom Y labels. A function
|
|
|
20 |
<code class="function">get_label()</code> is defined to map the Y tick value
|
|
|
21 |
into a string from an array of strings. This method allows the display
|
|
|
22 |
of arbitrary labels along the Y axis.
|
|
|
23 |
See <a class="xref" href="SetYLabelType.html" title="SetYLabelType"><span class="refentrytitle">SetYLabelType</span></a> for details.
|
|
|
24 |
</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
|
|
|
25 |
# PHPlot Example - Bubble Plot
|
|
|
26 |
require_once 'phplot.php';
|
|
|
27 |
|
|
|
28 |
# Array of custom labels for the Y axis. See the get_label callback.
|
|
|
29 |
$y_labels = array("", "Age\n12 and under", "Age 13-17", "Age 18-29",
|
|
|
30 |
"Age 30-39", "Age 40-54", "Age\n55 and older");
|
|
|
31 |
|
|
|
32 |
# Return the string for a Y label:
|
|
|
33 |
function get_label($value, $labels)
|
|
|
34 |
{
|
|
|
35 |
if (isset($labels[(int)$value])) return $labels[(int)$value];
|
|
|
36 |
return $value;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
# <=12 13-17 17-28 30-39 40-54 >=55
|
|
|
40 |
$data = array(
|
|
|
41 |
array('Cherry', 1, 1, 2, 2, 4, 3, 3, 4, 3, 5, 5, 6, 6),
|
|
|
42 |
array('Apple', 2, 1, 9, 2, 7, 3, 4, 4, 7, 5, 3, 6, 7),
|
|
|
43 |
array('Pear', 3, '', 2, 2, 2, 3, 3, 4, 4, 5, 3, 6, 2),
|
|
|
44 |
array('Grape', 4, 1, 8, 2, 5, 3, 5, 4, 6, 5, 3, 6, 4),
|
|
|
45 |
array('Kiwi', 5, '', 0, 2, 3, 3, 4, 4, 4, 5, 5, 6, 2),
|
|
|
46 |
array('Banana', 6, 1, 5, 2, 4, 3, 6, 4, 3, 5, 3, 6, 4),
|
|
|
47 |
);
|
|
|
48 |
|
|
|
49 |
$plot = new PHPlot(600, 600);
|
|
|
50 |
$plot->SetTitle("Flavor Preference By Age Group");
|
|
|
51 |
$plot->SetDataType('data-data-xyz');
|
|
|
52 |
$plot->SetDataValues($data);
|
|
|
53 |
$plot->SetPlotType('bubbles');
|
|
|
54 |
$plot->SetDataColors('yellow'); // Use same color for all data sets
|
|
|
55 |
$plot->SetDrawPlotAreaBackground(True);
|
|
|
56 |
$plot->SetPlotBgColor('plum');
|
|
|
57 |
$plot->SetLightGridColor('red'); // Change grid color to make it visible
|
|
|
58 |
$plot->SetImageBorderType('plain');
|
|
|
59 |
$plot->SetPlotBorderType('full');
|
|
|
60 |
$plot->SetXTickIncrement(1); // For grid line spacing
|
|
|
61 |
$plot->SetYTickIncrement(1);
|
|
|
62 |
$plot->SetPlotAreaWorld(0, 0, 6.5, 6.5);
|
|
|
63 |
# Establish the handler for the Y label text:
|
|
|
64 |
$plot->SetYLabelType('custom', 'get_label', $y_labels);
|
|
|
65 |
$plot->SetXTickPos('both'); // Tick marks on both sides
|
|
|
66 |
$plot->SetYTickPos('both'); // Tick marks on top and bottom too
|
|
|
67 |
$plot->SetXDataLabelPos('both'); // X axis data labels top and bottom
|
|
|
68 |
$plot->SetYTickLabelPos('both'); // Y axis labels left and right
|
|
|
69 |
$plot->SetDrawXGrid(True);
|
|
|
70 |
$plot->DrawGraph();
|
|
|
71 |
</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>
|