CCATSL has several routines for plotting two-dimensional data.
CurveCL is the usual choice
for plotting
=
when you are able to
work out what
will be for arbitrary
.
Sometimes you only know the value of
at a
sequence of points
when you probably want to use the routine
XYCurveCL instead. (This routine is also
the way to plot arbitrary collections of points.) Finally, CCATSL can
draw histograms, using
XYHistogramCL.
For some of these routines, you may find it helpful to use
XYSortCL
to re-order the arrays storing the
and
-values so that the
-values are in increasing order.
CurveCLCurveCL is the simplest CCATSL graphics routine and is suitable for drawing
a curve of the form
| void CurveCL ( |
double (*g)(double x), |
| double xlow, |
|
| double xhi, |
|
| int npts, |
|
| ColourCT colour, |
|
| AxisModeCT axismode); |
|
| g |
The function |
|
| xlo, xhi |
Specifies the interval [xlo,xhi] over which |
|
| npts |
The number of points at which |
|
| colour |
The colour of the graph, . | |
| axismode |
Determines whether CCATSL should try to work out scales for
the AUTOAXES), and
here
for more information. |
Here is a simple example using CurveCL:
|
/* /example/chapter3/dcurve1.c */
#include <catam.h>
double f(double x)
{
return exp(-x*x);
}
int MainCL(void)
{
CurveCL(f,-3,3,50,RedCC,AUTOAXES);
return 0;
}
|
XYCurveCL
| void XYCurveCL ( |
double *xp, |
| double *yp, |
|
| int npts, |
|
| int ncols, |
|
| DrawDataCT option, |
|
| ColourCT colour, |
|
| AxisModeCT axismode); |
|
| xp |
Array holding the sequence
|
|
| yp |
Array holding the sequence
|
|
| npts |
The number of points in the sequence. | |
| ncols |
Normally ncols=1.
(In general, ncols should be the size of the second dimension in
the declarations of the arrays
xp and yp.) |
|
| option |
Specifies how the points should appear. Popular choices are JOIN,
to have the points joined up with straight lines, or PLUS to have each point
marked with a +. You can find the full list of plot symbols
here. |
|
| colour |
The colour of the graph, such as RedCC. |
|
| axismode |
Determines whether CCATSL should try to work out
scales for the axes automatically. See the example below for the most common
usage (AUTOAXES), and
here
for more information. |
|
/* /examples/chapter3/ddata1.c */
#include <catam.h>
int MainCL(void)
{
double x[50];
double y[50];
double r;
int i;
for (i=0; i<50; i++) {
r=i/49.0-0.5; /* from -0.5 to +0.5 */
x[i]=r;
y[i]=r*r*(1-r);
}
XYCurveCL(x,y,50,1,TRIANGLE,RedCC,AUTOAXES);
return 0;
}
|
XYHistogramCLXYSortCL to sort the
arrays first.
| void XYHistogramCL ( |
double *xp, |
| double *yp, |
|
| int n, |
|
| int ncols, |
|
| double width, |
|
| double disp, |
|
| ColourCT colour, |
|
| AxisModeCT axismode); |
|
| xp |
Array holding the sequence
|
|
| yp |
Array holding the sequence
|
|
| n |
The number of points in the sequence. | |
| ncols |
Normally ncols=1 (see below). (In general, ncols is the size
of the second dimension in the declarations of the arrays
xp and yp.) |
|
| width |
The width of the bars as a proportion of (the common value of)
width=1 will make each bar
appear flush with its neighbours while
width=0.9 will leave a small gap between adjacent bars. |
|
| disp |
Specifies the offset of the disp=-0.5 places the centre of the disp=0 will put the left hand side of the |
|
| colour |
The colour used to fill the bars, such as RedCC. |
|
| axismode |
Determines whether CCATSL should work out
scales for the axes automatically. See the example below for the most common
usage (AUTOAXES), and here
for more information. |
|
/* /examples/chapter3/histo2d.c */
#include <catam.h>
int MainCL(void)
{
double x[10];
double y[10];
int i;
for (i=0; i<10; i++) {
x[i]=i;
y[i]=exp(-i/3.0);
}
XYHistogramCL(x,y,10,1,0.9,-0.5,RedCC,AUTOAXES);
return 0;
}
|