next up previous contents index
Next: Three-dimensional data Up: Plotting graphs Previous: Plotting graphs   Contents   Index


Two-dimensional data

CCATSL has several routines for plotting two-dimensional data. CurveCL is the usual choice for plotting $y$ = $g(x)$ when you are able to work out what $g(x)$ will be for arbitrary $x$. Sometimes you only know the value of $g(x)$ at a sequence of points $(x_i)_{i=1}^n$ 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 $x$ and $y$-values so that the $x$-values are in increasing order.


CurveCL

CurveCL is the simplest CCATSL graphics routine and is suitable for drawing a curve of the form $y=g(x)$ when $g(x)$ is easily computable.

  void CurveCL ( double (*g)(double x),
  double xlow,
  double xhi,
  int npts,
  ColourCT colour,
  AxisModeCT axismode);

  g The function $g$. See below for an example.
  xlo, xhi Specifies the interval [xlo,xhi] over which $g(x)$ is to be plotted.
  npts The number of points at which $g$ should be sampled.
  colour The colour of the graph, .
  axismode Determines whether CCATSL should try to work out scales for the $x$ and $y$ axes automatically. See the example below for the most common usage (AUTOAXES), and here for more information.

Here is a simple example using CurveCL:


screenshot of dcurve1.pas
  
/*   /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

This routine plots a sequence of points $(x_i,y_i)_{i=1}^n$. The points can be plotted individually using a variety of symbols (dots, plus signs, triangles etc.), or they may be joined together with straight lines.

  void XYCurveCL ( double *xp,
  double *yp,
  int npts,
  int ncols,
  DrawDataCT option,
  ColourCT colour,
  AxisModeCT axismode);

  xp Array holding the sequence $x_1,\ldots{,}\,x_n$.
  yp Array holding the sequence $y_1,\ldots{,}\,y_n$.
  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.


screenshot of ddata1.pas
  
/*   /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;
}


XYHistogramCL

This routine produces a two-dimensional histogram from a dataset; the data must be in the form $(x_i,y_i)_{i=1}^n$ where $x_i$ is the location of the $i$th bar and $y_i$ is its corresponding height. (The centre of the $i$th bar will be at a position equal to $x_i$ plus some specified offset, which can be arbitrary but must be the same for all $i$.) The $x_i$ should be equally spaced and monotone - you may want to use the routine XYSortCL 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 $x_1,\ldots{,}\,x_n$.
  yp Array holding the sequence $y_1,\ldots{,}\,y_n$.
  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) $x_{i+1}-x_i$. For example, 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 $i$th bar relative to $x_i$, in units of $x_{i+1}-x_i$. For example, disp=-0.5 places the centre of the $i$th bar at $x_i$ while disp=0 will put the left hand side of the $i$th bar at $x_i$.
  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.


screenshot of histo2d.pas
  
/*   /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;
}


next up previous contents index
Next: Three-dimensional data Up: Plotting graphs Previous: Plotting graphs   Contents   Index
CATAM admin 2010-02-23