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.35. Example - Legend with Shape Markers</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-outbreak.html" title="5.34. Example - Overlaying Plots" /><link rel="next" href="ex-legendpos.html" title="5.36. Example - Legend Positioning" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.35. Example - Legend with Shape Markers</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-outbreak.html">Prev</a> </td><th width="60%" align="
center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-legendpos.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-legendshape"></a>5.35. Example - Legend with Shape Markers</h2></div></div></div><p>
This example shows the standard legend appearance, followed by the same
plot with point shape markers in the legend instead of color boxes,
and again using a line plot with line markers.
Using point shapes in the legend was added in PHPlot-5.4.0.
These are useful if you need to be able to interpret the legend without color,
for example with monochrome printing, or for accessibility reasons.
Using line markers in the legend was added in PHPlot-6.0.0.
When used with varying line widths, this can reduce the dependency on color
to identify the plotted lines.
See <a class="xref" href="conc-otherelements.html#conc-legend" title="3.7.2. Legend">Section 3.7.2, “Legend”</a> for more on the plot legend.
</p><div class="example"><a id="example-legendshape"></a><p class="title"><strong>Example 5.35. Legend with Color Boxes or Shape Markers</strong></p><div class="example-contents"><p>
First, here is the standard legend with color boxes.
</p><div class="informalfigure"><div class="mediaobject"><img src="examples/legendshape.png" alt="Legend with Color Boxes" /></div></div><pre class="programlisting"><?php
# PHPlot Example: Linepoints plot with legend using color boxes or shape markers
require_once 'phplot.php';
# The variable $use_shapes can be set to TRUE in another
# script which calls this script, to use shape markers
# rather than color boxes in the legend.
if (empty($use_shapes)) $use_shapes = FALSE;
# The variable $plot_type can be set in another script as well.
if (empty($plot_type)) $plot_type = 'linepoints';
# Use data labels to display only the points we want,
# but specify the same values for X to get the correct
# spacing.
$data = array(
array('1990', 1990, 41308, 21015, 62634),
array('1995', 1995, 44310, 13883, 61529),
array('2000', 2000, 46772, 9000, 59421),
array('2004', 2004, 46887, 7738, 57754),
array('2006', 2006, 45441, 6888, 53179),
array('2008', 2008, 42757, 5840, 49115),
);
$legend_text = array('Morning Papers', 'Evening Papers', 'Sunday Papers');
$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('plain'); // Improves presentation in the manual
$plot->SetTitle("US Daily Newspaper Circulation\n"
. $plot_type . ' plot with SetLegendUseShapes('
. ($use_shapes ? 'True' : 'False') . ')');
$plot->SetPlotType($plot_type);
$plot->SetDataType('data-data');
$plot->SetDataValues($data);
$plot->SetPlotAreaWorld(1988, 0, 2010, 80000);
$plot->SetYTickIncrement(10000);
$plot->SetLegend($legend_text);
$plot->SetXTickPos('none');
$plot->SetDrawXDataLabelLines(True);
$plot->SetLegendUseShapes($use_shapes); // Use color boxes or shapes
$plot->SetPointSizes(12); // Make points bigger for visibility
$plot->SetLineStyles('solid'); // Make all lines solid
$plot->SetLineWidths(2); // Make all lines thicker
$plot->DrawGraph();
</pre><p>
Changing the call to <a class="xref" href="SetLegendUseShapes.html" title="SetLegendUseShapes"><span class="refentrytitle">SetLegendUseShapes</span></a> results in a
legend using point shapes instead of color boxes.
(This requires PHPlot-5.4.0 or later.)
</p><div class="informalfigure"><div class="mediaobject"><img src="examples/legendshape1.png" alt="Legend with Point Shapes" /></div></div><pre class="programlisting"><?php
# PHPlot Example: Linepoints plot with legend using shape markers
# This sets a variable and calls the script directly above.
$use_shapes = TRUE;
require_once 'legendshape.php';
</pre><p>
With a line plot, the shape markers are line segments rather than point
markers.
(This requires PHPlot-6.0.0 or later.)
</p><div class="informalfigure"><div class="mediaobject"><img src="examples/legendshape2.png" alt="Legend with Line Markers" /></div></div><pre class="programlisting"><?php
# PHPlot Example: Line plot with legend using line markers
# This sets variables and calls the script directly above.
$use_shapes = TRUE;
$plot_type = 'lines';
require_once 'legendshape.php';
</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-outbreak.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-legendpos.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.34. Example - Overlaying Plots </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.36. Example - Legend Positioning</td></tr></table></div></body></html>