1 | <?php // content="text/plain; charset=utf-8" |
---|
2 | require_once ('jpgraph/jpgraph.php'); |
---|
3 | require_once ('jpgraph/jpgraph_line.php'); |
---|
4 | require_once ('jpgraph/jpgraph_scatter.php'); |
---|
5 | require_once ('jpgraph/jpgraph_regstat.php'); |
---|
6 | |
---|
7 | // Original data points |
---|
8 | $xdata = array(1,3,5,7,9,12,15,17.1); |
---|
9 | $ydata = array(5,1,9,6,4,3,19,12); |
---|
10 | |
---|
11 | // Get the interpolated values by creating |
---|
12 | // a new Spline object. |
---|
13 | $spline = new Spline($xdata,$ydata); |
---|
14 | |
---|
15 | // For the new data set we want 40 points to |
---|
16 | // get a smooth curve. |
---|
17 | list($newx,$newy) = $spline->Get(50); |
---|
18 | |
---|
19 | // Create the graph |
---|
20 | $g = new Graph(300,200); |
---|
21 | $g->SetMargin(30,20,40,30); |
---|
22 | $g->title->Set("Natural cubic splines"); |
---|
23 | $g->title->SetFont(FF_ARIAL,FS_NORMAL,12); |
---|
24 | $g->subtitle->Set('(Control points shown in red)'); |
---|
25 | $g->subtitle->SetColor('darkred'); |
---|
26 | $g->SetMarginColor('lightblue'); |
---|
27 | |
---|
28 | //$g->img->SetAntiAliasing(); |
---|
29 | |
---|
30 | // We need a linlin scale since we provide both |
---|
31 | // x and y coordinates for the data points. |
---|
32 | $g->SetScale('linlin'); |
---|
33 | |
---|
34 | // We want 1 decimal for the X-label |
---|
35 | $g->xaxis->SetLabelFormat('%1.1f'); |
---|
36 | |
---|
37 | // We use a scatterplot to illustrate the original |
---|
38 | // contro points. |
---|
39 | $splot = new ScatterPlot($ydata,$xdata); |
---|
40 | |
---|
41 | // |
---|
42 | $splot->mark->SetFillColor('red@0.3'); |
---|
43 | $splot->mark->SetColor('red@0.5'); |
---|
44 | |
---|
45 | // And a line plot to stroke the smooth curve we got |
---|
46 | // from the original control points |
---|
47 | $lplot = new LinePlot($newy,$newx); |
---|
48 | $lplot->SetColor('navy'); |
---|
49 | |
---|
50 | // Add the plots to the graph and stroke |
---|
51 | $g->Add($lplot); |
---|
52 | $g->Add($splot); |
---|
53 | $g->Stroke(); |
---|
54 | |
---|
55 | ?> |
---|
56 | |
---|