Programming and Graphics

(Kiana) #1

7.5 A graph with axes 221


color (BLACK);
int marker = 3;

for(int i=0; i<n; i++)
{
if( xd[i]>xmin && xd[i]<xmax && yd[i]>ymin && yd[i]<ymax)
drawmarker2d (xd[i],yd[i],marker,xmin,xmax,ymin,ymax);
}

//--- Plot the data:

int Icheck=1;
drawline2d (n,xd,yd,xmin,xmax,ymin,ymax,Icheck);

//--- Draw a box:

move2 (xmin,ymin);
draw2 (xmax,ymin);

draw2 (xmin,ymin);

//--- Wait until a key is pressed:

char kbd = char(getkey());

return 0;
}

The graphics output of the code is shown in Figure 7.4.1.


Problems


7.4.1. Modify the functiondrawmarker2dto include an option for drawing
(a) a solid circle, and (b) a filled triangle with a color of your choice.

7.4.2. Modify the codeplot2dsimple.ccso that the data points are (a) gen-
erated in a function, or (b) read from a file.

7.4.3. Modify the codeplot2dsimple.cc so that the graph is printed in a
graphics file.

7.5 A graph with axes


To plot scientific data, we require axes with tick marks, corresponding numerical
labels, and axis labels.

Free download pdf