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.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 width="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>
|
|
|
3 |
This example shows the use of <a class="xref" href="SetYTickAnchor.html" title="SetYTickAnchor"><span class="refentrytitle">SetYTickAnchor</span></a> to tell PHPlot
|
|
|
4 |
that we want a tick mark and label at a specific value.
|
|
|
5 |
</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>
|
|
|
6 |
First, here is the example without a Y tick anchor. Note that there is no Y
|
|
|
7 |
tick mark or label at the X axis Y=0.
|
|
|
8 |
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
|
|
|
9 |
The script uses <a class="xref" href="SetPlotAreaWorld.html" title="SetPlotAreaWorld"><span class="refentrytitle">SetPlotAreaWorld</span></a> to set the Y axis range
|
|
|
10 |
to -3.5 to 13.5. This is used here to illustrate the need for setting a Y
|
|
|
11 |
tick anchor, and the effect of setting the Y tick anchor at 0. Without
|
|
|
12 |
<code class="function">SetPlotAreaWorld()</code>, PHPlot-6.0.0 and later (but not
|
|
|
13 |
older versions) will automatically calculate the Y range such that a tick
|
|
|
14 |
mark will be at Y=0 even without <code class="function">SetYTickAnchor(0)</code>.
|
|
|
15 |
</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
|
|
|
16 |
# PHPlot Example: Using a Y tick anchor to force a tick at 0.
|
|
|
17 |
# This requires PHPlot >= 5.4.0
|
|
|
18 |
require_once 'phplot.php';
|
|
|
19 |
|
|
|
20 |
# The variable $set_anchor can be set to a value in another script
|
|
|
21 |
# which calls this script, to set the Y anchor to that value.
|
|
|
22 |
if (isset($set_anchor))
|
|
|
23 |
$case = "with Y tick anchor at $set_anchor";
|
|
|
24 |
else
|
|
|
25 |
$case = "without Y tick anchor";
|
|
|
26 |
|
|
|
27 |
# Function to plot:
|
|
|
28 |
function f($x)
|
|
|
29 |
{
|
|
|
30 |
if ($x == 0) return 0;
|
|
|
31 |
return 5 + 8 * sin(200 * M_PI / $x);
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
$data = array();
|
|
|
35 |
for ($x = 0; $x < 500; $x++)
|
|
|
36 |
$data[] = array('', $x, f($x));
|
|
|
37 |
|
|
|
38 |
$plot = new PHPlot(800, 600);
|
|
|
39 |
$plot->SetImageBorderType('plain'); // For presentation in the manual
|
|
|
40 |
$plot->SetTitle("Example $case");
|
|
|
41 |
$plot->SetDataType('data-data');
|
|
|
42 |
$plot->SetDataValues($data);
|
|
|
43 |
$plot->SetPlotType('lines');
|
|
|
44 |
$plot->SetXTickLabelPos('none');
|
|
|
45 |
$plot->SetXTickPos('none');
|
|
|
46 |
# See notes in reference manual on this:
|
|
|
47 |
$plot->SetPlotAreaWorld(NULL, -3.5, NULL, 13.5);
|
|
|
48 |
|
|
|
49 |
if (isset($set_anchor))
|
|
|
50 |
$plot->SetYTickAnchor($set_anchor);
|
|
|
51 |
|
|
|
52 |
$plot->DrawGraph();
|
|
|
53 |
</pre><p>
|
|
|
54 |
Using <a class="xref" href="SetYTickAnchor.html" title="SetYTickAnchor"><span class="refentrytitle">SetYTickAnchor</span></a>(0) tells PHPlot to shift the Y tick
|
|
|
55 |
marks and labels to place a tick mark at Y=0.
|
|
|
56 |
</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
|
|
|
57 |
# PHPlot Example: Using a Y tick anchor to force a tick at 0.
|
|
|
58 |
# This sets a variable and calls the script directly above.
|
|
|
59 |
$set_anchor = 0;
|
|
|
60 |
require_once 'ytickanchor.php';
|
|
|
61 |
</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>
|