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.2. Example - Line Plot: Functions</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="examples.html" title="Chapter 5. PHPlot Examples" /><link rel="next" href="ex-area1.html" title="5.3. Example - Area Plot" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.2. Example - Line Plot: Functions</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="examples.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-area1.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-lines2"></a>5.2. Example - Line Plot: Functions</h2></div></div></div><p>
|
|
|
3 |
This is a line plot showing the graph of sin(x) and cos(x).
|
|
|
4 |
This uses quite a few of the PHPlot style control functions
|
|
|
5 |
to tune the appearance of the plot.
|
|
|
6 |
</p><div class="example"><a id="example-lines2"></a><p class="title"><strong>Example 5.2. Line Plot: Functions</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="examples/lines2.png" alt="Line Plot Functions Example" /></div></div><pre class="programlisting"><?php
|
|
|
7 |
# PHPlot Example: Line graph, 2 lines
|
|
|
8 |
require_once 'phplot.php';
|
|
|
9 |
|
|
|
10 |
# Generate data for:
|
|
|
11 |
# Y1 = sin(x)
|
|
|
12 |
# Y2 = cos(x)
|
|
|
13 |
$end = M_PI * 2.0;
|
|
|
14 |
$delta = $end / 20.0;
|
|
|
15 |
$data = array();
|
|
|
16 |
for ($x = 0; $x <= $end; $x += $delta)
|
|
|
17 |
$data[] = array('', $x, sin($x), cos($x));
|
|
|
18 |
|
|
|
19 |
$plot = new PHPlot(800, 600);
|
|
|
20 |
$plot->SetImageBorderType('plain');
|
|
|
21 |
|
|
|
22 |
$plot->SetPlotType('lines');
|
|
|
23 |
$plot->SetDataType('data-data');
|
|
|
24 |
$plot->SetDataValues($data);
|
|
|
25 |
|
|
|
26 |
# Main plot title:
|
|
|
27 |
$plot->SetTitle('Line Plot, Sin and Cos');
|
|
|
28 |
|
|
|
29 |
# Make a legend for the 2 functions:
|
|
|
30 |
$plot->SetLegend(array('sin(t)', 'cos(t)'));
|
|
|
31 |
|
|
|
32 |
# Select a plot area and force ticks to nice values:
|
|
|
33 |
$plot->SetPlotAreaWorld(0, -1, 6.8, 1);
|
|
|
34 |
|
|
|
35 |
# Even though the data labels are empty, with numeric formatting they
|
|
|
36 |
# will be output as zeros unless we turn them off:
|
|
|
37 |
$plot->SetXDataLabelPos('none');
|
|
|
38 |
|
|
|
39 |
$plot->SetXTickIncrement(M_PI / 8.0);
|
|
|
40 |
$plot->SetXLabelType('data');
|
|
|
41 |
$plot->SetPrecisionX(3);
|
|
|
42 |
|
|
|
43 |
$plot->SetYTickIncrement(0.2);
|
|
|
44 |
$plot->SetYLabelType('data');
|
|
|
45 |
$plot->SetPrecisionY(1);
|
|
|
46 |
|
|
|
47 |
# Draw both grids:
|
|
|
48 |
$plot->SetDrawXGrid(True);
|
|
|
49 |
$plot->SetDrawYGrid(True);
|
|
|
50 |
|
|
|
51 |
$plot->DrawGraph();
|
|
|
52 |
</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="examples.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-area1.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 5. PHPlot Examples </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.3. Example - Area Plot</td></tr></table></div></body></html>
|