HowToC:DrawLines

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 22:19, 10 December 2007
S2plot admin (Talk | contribs)

← Previous diff
Current revision
S2plot admin (Talk | contribs)
(Function Overview)
Line 1: Line 1:
-==Drawing Points==+==Drawing Lines==
 +As with points, you can use either the PGPLOT-style functions or the native S2PLOT routines.
-===Points example===+===Lines example===
-Copy and paste the following code, and save the file as <tt>s2points.c</tt>+Copy and paste the following code, and save the file as <tt>s2lines.c</tt>
<code><pre> <code><pre>
Line 18: Line 19:
s2opend("/?",argc,argv); /* Which S2PLOT device to open? */ s2opend("/?",argc,argv); /* Which S2PLOT device to open? */
s2swin(xmin, xmax, ymin, ymax, zmin, zmax); /* Set the display coordinates */ s2swin(xmin, xmax, ymin, ymax, zmin, zmax); /* Set the display coordinates */
 +
 + float x[10], y[10], z[10];
 + int i;
 + for (i=0;i<10;i++) {
 + x[i] = drand48()*(xmax-xmin) + xmin;
 + y[i] = drand48()*(ymax-ymin) + ymin;
 + z[i] = drand48()*(zmax-zmin) + zmin;
 + }
 + s2line(10, x, y, z);
s2show(1); /* Hand over to the display */ s2show(1); /* Hand over to the display */
Line 25: Line 35:
</pre></code> </pre></code>
-Compile using: <tt>cbuild.csh s2example<tt> and then run by typing <tt>s2example</tt> at the command prompt.+The line-style and thickness are controlled using the s2sls and s2slw functions. To see what they do, put the following code:
 + s2sls(style);
 + s2slw(width);
 +before the s2line function call, where <tt>style</tt> is an integer that selects one of:
 +# 1 = normal line
 +# 2 = dashed
 +# 3 = dot-dash-dot-dash
 +# 4 = dotted
 +# 5 = dash-dot-dot-dot
 +and <tt>width</tt> is the line width in pixels.
 + 
===Experiment for yourself=== ===Experiment for yourself===
Line 34: Line 54:
For more information on the functions we have introduced so far, see: For more information on the functions we have introduced so far, see:
 +* [[Function:s2line|s2line]]
 +* [[Function:s2slw|s2slw]]
 +* [[Function:s2sls|s2sls]]
 +* [[Function:s2arro|s2arro]]
 +* [[Function:s2sah|s2sah]]
 +* [[Function:s2qah|s2qah]]
 +* [[Function:s2errb|s2errb]]
 +* [[Function:ns2line|ns2line]]
 +* [[Function:ns2vline|ns2line]]
 +* [[Function:ns2thline|ns2line]]
 +* [[Function:ns2vthline|ns2line]]
 +* [[Function:ns2cline|ns2line]]
 +* [[Function:ns2vcline|ns2line]]
=== Common Problems=== === Common Problems===

Current revision

Contents

Drawing Lines

As with points, you can use either the PGPLOT-style functions or the native S2PLOT routines.

Lines example

Copy and paste the following code, and save the file as s2lines.c

#include <stdio.h>
#include <stdlib.h>
#include "s2plot.h"

int main(int argc, char *argv[])
{
   float xmin = -1, xmax = +1;          /* X data range */
   float ymin = -1, ymax = +1;          /* Y data range */
   float zmin = -1, zmax = +1;          /* Z data range */

   s2opend("/?",argc,argv);             /* Which S2PLOT device to open? */
   s2swin(xmin, xmax, ymin, ymax, zmin, zmax);  /* Set the display coordinates */

   float x[10], y[10], z[10];
   int i;
   for (i=0;i<10;i++) {
      x[i] = drand48()*(xmax-xmin) + xmin;
      y[i] = drand48()*(ymax-ymin) + ymin;
      z[i] = drand48()*(zmax-zmin) + zmin;
   }
   s2line(10, x, y, z);

   s2show(1);                           /* Hand over to the display */

   return 1;
}

The line-style and thickness are controlled using the s2sls and s2slw functions. To see what they do, put the following code:

  s2sls(style);
  s2slw(width);

before the s2line function call, where style is an integer that selects one of:

  1. 1 = normal line
  2. 2 = dashed
  3. 3 = dot-dash-dot-dash
  4. 4 = dotted
  5. 5 = dash-dot-dot-dot

and width is the line width in pixels.


Experiment for yourself

Function Overview

For more information on the functions we have introduced so far, see:

Common Problems

Test code: s2points.c

This is the full test code for the point-drawing example.

Where to Next?

Personal tools