| 1 |
lars |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
|
|
2 |
<HTML>
|
|
|
3 |
<HEAD>
|
|
|
4 |
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1">
|
|
|
5 |
<LINK REL="Start" HREF="index.html">
|
|
|
6 |
<LINK REL="Contents" HREF="toc.html">
|
|
|
7 |
<LINK REL="Prev" HREF="8115Usingaccumulatedlinegraphs.html">
|
|
|
8 |
<LINK REL="Next" HREF="8117Addingplotmarkstoalineplot.html">
|
|
|
9 |
<STYLE TYPE="text/css"><!--
|
|
|
10 |
BODY { font-family: serif }
|
|
|
11 |
H1 { font-family: sans-serif }
|
|
|
12 |
H2 { font-family: sans-serif }
|
|
|
13 |
H3 { font-family: sans-serif }
|
|
|
14 |
H4 { font-family: sans-serif }
|
|
|
15 |
H5 { font-family: sans-serif }
|
|
|
16 |
H6 { font-family: sans-serif }
|
|
|
17 |
SUB { font-size: smaller }
|
|
|
18 |
SUP { font-size: smaller }
|
|
|
19 |
PRE { font-family: monospace }
|
|
|
20 |
A { text-decoration: none }
|
|
|
21 |
--></STYLE>
|
|
|
22 |
</HEAD>
|
|
|
23 |
<BODY>
|
|
|
24 |
<A HREF="toc.html">Contents</A>
|
|
|
25 |
<A HREF="8115Usingaccumulatedlinegraphs.html">Previous</A>
|
|
|
26 |
<A HREF="8117Addingplotmarkstoalineplot.html">Next</A>
|
|
|
27 |
<HR NOSHADE>
|
|
|
28 |
<H3><A NAME="8_1_16">8.1.16 Constructing smooth line plots with Cubic
|
|
|
29 |
Splines</A></H3>
|
|
|
30 |
<P> If you only have access to a few data points but still want a smooth
|
|
|
31 |
curve between those data points JpGraph can help you achieving that by
|
|
|
32 |
letting you construct cubic splines. If you never have heard of cubic
|
|
|
33 |
splines before, don't worry. You only have to supply the data points
|
|
|
34 |
you know tell JpGraph how many interpolated points in total you want in
|
|
|
35 |
the graph. JpGraph will now take care of constructing a smooth curve
|
|
|
36 |
between all you data points. The new, smooth, curve will be made up of
|
|
|
37 |
exactly as many interpolated points as you have specified.</P>
|
|
|
38 |
<P> To construct a spline you need both the X and Y coordinates for the
|
|
|
39 |
known data points.</P>
|
|
|
40 |
<P> You start by constructing a new <A href="">Spline</A> instance. To
|
|
|
41 |
get access to the Spline class you must first remember to include the
|
|
|
42 |
file "jpgraph_regstat.php". You instantiate this class by calling it
|
|
|
43 |
with your two known data arrays (X and Y) as follows.<DIV class="phpscript">
|
|
|
44 |
<CODE><FONT color="#000000"> <FONT color="#0000BB"> $spline </FONT><FONT color="#007700">
|
|
|
45 |
= new </FONT><FONT color="#0000BB">Spline</FONT><FONT color="#007700">(</FONT><FONT
|
|
|
46 |
color="#0000BB">$xdata</FONT><FONT color="#007700">,</FONT><FONT color="#0000BB">
|
|
|
47 |
$ydata</FONT><FONT color="#007700">);</FONT><FONT color="#0000BB"></FONT>
|
|
|
48 |
</FONT></CODE></DIV></P>
|
|
|
49 |
<P>This call initializes the spline with the data points you have. These
|
|
|
50 |
data points are also known as<I> Control points</I> for the spline.
|
|
|
51 |
This helper class doesn't draw any line itself. Instead it is merely
|
|
|
52 |
used to get a new (larger) data array which have all the interpolated
|
|
|
53 |
values. You then use these new value in your plot. This way give you
|
|
|
54 |
great flexibility in how you want to use this interpolated data.</P>
|
|
|
55 |
<P> Continuing the above line we now use the <A href="">Spline::Get()</A>
|
|
|
56 |
method to get an interpolated array containing a specified number of
|
|
|
57 |
points. So for example the line<DIV class="phpscript"><CODE><FONT color="#000000">
|
|
|
58 |
<FONT color="#0000BB"> </FONT><FONT color="#007700">list(</FONT><FONT color="#0000BB">
|
|
|
59 |
$sdatax</FONT><FONT color="#007700">,</FONT><FONT color="#0000BB">
|
|
|
60 |
$sdatay</FONT><FONT color="#007700">) = </FONT><FONT color="#0000BB">
|
|
|
61 |
$spline</FONT><FONT color="#007700">-></FONT><FONT color="#0000BB">Get</FONT><FONT
|
|
|
62 |
color="#007700">(</FONT><FONT color="#0000BB">50</FONT><FONT color="#007700">
|
|
|
63 |
);</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV></P>
|
|
|
64 |
<P>Will construct the two new data arrays '$sdatax' and '$sdatay' which
|
|
|
65 |
contains 50 data points. These two arrays are constructed from the
|
|
|
66 |
control point we specified when we created the '$spline' object.</P>
|
|
|
67 |
<P> You would then use these two new data array in exactly the same way
|
|
|
68 |
as you would form ordinary data vectors.</P>
|
|
|
69 |
<P> The following example illustrates this<DIV class="example">
|
|
|
70 |
<BR> <A href="exframes/frame_splineex1.html" target="blank"><IMG border="0"
|
|
|
71 |
HEIGHT="200" src="img/splineex1.png" WIDTH="300"></A>
|
|
|
72 |
<BR><B>Figure 26:</B> Using spline to get a smooth curve between the
|
|
|
73 |
control points. <A href="exframes/frame_splineex1.html" target="blank">
|
|
|
74 |
[src]</A>
|
|
|
75 |
<P></P>
|
|
|
76 |
</DIV></P>
|
|
|
77 |
<P> In order to make the example more interesting we actually use two
|
|
|
78 |
plots. First a line plot to get the smooth curve and then a standard
|
|
|
79 |
scatter plot which is used to illustrate where the control points are.</P>
|
|
|
80 |
<HR NOSHADE>
|
|
|
81 |
<A HREF="toc.html">Contents</A>
|
|
|
82 |
<A HREF="8115Usingaccumulatedlinegraphs.html">Previous</A>
|
|
|
83 |
<A HREF="8117Addingplotmarkstoalineplot.html">Next</A>
|
|
|
84 |
</BODY>
|
|
|
85 |
</HTML>
|