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.37. Example - Setting a Y Tick Anchor</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-legendpos.html" title="5.36. Example - Legend Positioning" /><link rel="next" href="ex-xtickanchor.html" title="5.38. Example - Hourly Data Using X Tick Anchor" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.37. Example - Setting a Y Tick Anchor</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-legendpos.html">Prev</a> </td><th widt
h="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-xtickanchor.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-ytickanchor"></a>5.37. Example - Setting a Y Tick Anchor</h2></div></div></div><p>
This example shows the use of <a class="xref" href="SetYTickAnchor.html" title="SetYTickAnchor"><span class="refentrytitle">SetYTickAnchor</span></a> to tell PHPlot
that we want a tick mark and label at a specific value.
</p><div class="example"><a id="example-ytickanchor"></a><p class="title"><strong>Example 5.37. Setting a Y Tick Anchor</strong></p><div class="example-contents"><p>
First, here is the example without a Y tick anchor. Note that there is no Y
tick mark or label at the X axis Y=0.
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
The script uses <a class="xref" href="SetPlotAreaWorld.html" title="SetPlotAreaWorld"><span class="refentrytitle">SetPlotAreaWorld</span></a> to set the Y axis range
to -3.5 to 13.5. This is used here to illustrate the need for setting a Y
tick anchor, and the effect of setting the Y tick anchor at 0. Without
<code class="function">SetPlotAreaWorld()</code>, PHPlot-6.0.0 and later (but not
older versions) will automatically calculate the Y range such that a tick
mark will be at Y=0 even without <code class="function">SetYTickAnchor(0)</code>.
</p></div><div class="informalfigure"><div class="mediaobject"><img src="examples/ytickanchor.png" alt="Setting a Y Tick Anchor - 1" /></div></div><pre class="programlisting"><?php
# PHPlot Example: Using a Y tick anchor to force a tick at 0.
# This requires PHPlot >= 5.4.0
require_once 'phplot.php';
# The variable $set_anchor can be set to a value in another script
# which calls this script, to set the Y anchor to that value.
if (isset($set_anchor))
$case = "with Y tick anchor at $set_anchor";
else
$case = "without Y tick anchor";
# Function to plot:
function f($x)
{
if ($x == 0) return 0;
return 5 + 8 * sin(200 * M_PI / $x);
}
$data = array();
for ($x = 0; $x < 500; $x++)
$data[] = array('', $x, f($x));
$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('plain'); // For presentation in the manual
$plot->SetTitle("Example $case");
$plot->SetDataType('data-data');
$plot->SetDataValues($data);
$plot->SetPlotType('lines');
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
# See notes in reference manual on this:
$plot->SetPlotAreaWorld(NULL, -3.5, NULL, 13.5);
if (isset($set_anchor))
$plot->SetYTickAnchor($set_anchor);
$plot->DrawGraph();
</pre><p>
Using <a class="xref" href="SetYTickAnchor.html" title="SetYTickAnchor"><span class="refentrytitle">SetYTickAnchor</span></a>(0) tells PHPlot to shift the Y tick
marks and labels to place a tick mark at Y=0.
</p><div class="informalfigure"><div class="mediaobject"><img src="examples/ytickanchor1.png" alt="Setting a Y Tick Anchor - 2" /></div></div><pre class="programlisting"><?php
# PHPlot Example: Using a Y tick anchor to force a tick at 0.
# This sets a variable and calls the script directly above.
$set_anchor = 0;
require_once 'ytickanchor.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-legendpos.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-xtickanchor.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.36. Example - Legend Positioning </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.38. Example - Hourly Data Using X Tick Anchor</td></tr></table></div></body></html>