We have provided both simple programs to help you get started and more
complicated programs to illustrate how some of the GraphiC features can
be used to enhance your plots. You are free to use these programs as “boiler
plate” for use in developing your own applications.
Annotated GraphiC Plot (Sample.C)
/****************************************************************************
(c) 1984 - 2003 by Scientific Endeavors Corporation.
All rights reserved.
This program plots a single curve on a set of 2-D linear axes. Except for
color(), sympick(), and grid(), this simple example program uses only
the minimum calls needed to produce a GraphiC plot.
****************************************************************************/
#include <graphic.h> /* Include all needed files */
#if TCQ /* Set stack for Borland (Turbo) C */
extern unsigned _stklen = 0x3000;
#endif
/****************************************************************************
Main program
****************************************************************************/
void GPC_MAIN(void)
{
float *x, *y;
int i, nxdiv, nydiv, npts;
npts = 301; /* The # of points in x and y vectors */
x = (float *)gpcalloc(npts, sizeof(float));
y = (float *)gpcalloc(npts, sizeof(float));
if(x == (float *)NULL || y == (float *)NULL) {
GPC_PUTS("SAMPLE: Could not allocate data arrays");
goto EndOfApp;
}
bgnplot(1, 'g', "sample.tkf"); /* Parameters: 1 - draw plot on screen
'g' - graphics mode
"sample.tkf" - .TKF file name */
startplot(WHITE);
metricunits(0); /* Ensure scaling in inch units */
font(1, "simplex.fnt", '\310'); /* Loads your chosen font */
page(9.0f, 6.884f); /* Sets the page size */
/* This is the same aspect ratio as 4095 by 3132 */
area2d(7.6f, 5.5f); /* Sets the area of the plot */
for (i = 0; i < npts; i++) { /* Generate data */
y[i] = .3f * i;
x[i] = (y[i] * y[i]) / 2.f;
}
color(BLACK); /* Axis names and heading will be black */
xname("\310X-Axis");
yname("Y-Axis");
heading("SAMPLE PLOT");
grid(9); /* Draws grid through tick marks, 9 - fine dot */
nxdiv = 5; /* Sets the desired # of x-axis divisions */
nydiv = 6; /* Sets the desired # of y-axis divisions */
color(GREEN); /* Green axes and labels */
scales(nxdiv, nydiv, x, y, npts); /* Draws and scales the axes */
color(RED); /* Red curve */
sympick(12); /* Filled circle symbols */
curve(x, y, npts, 10);
endplot(); /* Finishes plot and waits for instructions to exit or
draw next plot. Resets file pointers and defaults */
stopplot(); /* Close files, return to text mode, exit program */
EndOfApp:
gpcfree((void **)&x);
gpcfree((void **)&y);
}
Other Example Programs
-
BAR3D.C
An example showing how to plot 3-D bars.
-
BARTEST.C
Illustrates how to create a bar graph and uses the GraphiC legend facility.
-
BESS.C
An example of a shaded 3-D surface plot with a projected 2-D contour
plot and projected 2-D axes and grids.
-
CLRTEST.C
Semilog plot with a legend and string labels.
gwindow() excludes all drawing from a specified rectangle.
rightax() creates a second y axis on the right-side of the plot.
-
CNTTEST.C
Contour plots can be created with different line styles and colors,
and height labels may be placed on the contours.
-
D2TEST.C
Illustrates how you can place multiple plots in a single frame
by using a call to page() and pgshift() for each one.
-
D3TEST.C
A simple example of a 3-D surface plot. 3-D curves drawn uaing curv3d().
-
DELAYS.C
Uses the polar plot function wedge() to create a clock plot — a useful
way of showing discrete data with daily cycles.
-
ERFTEST.C
This example plots a curve on an error-function grid to display a normal
distribution.
-
EXH.C
A picture of the E and H vectors for an electromagnmetic plane wave.
-
FERMI.C
Illustrates why simultaneous plots are useful and how to make them.
-
FNTTEST.C
GraphiC allows you to access and manipulate numerous fonts.
-
INTEST.C
GraphiC's insert() command allows you to insert a TKF file into a new
plot.
-
JCONT.C
Stacked and projected contours are used in conjunction with a 3-D surface
-
LOGTEST.C
Examples of logarithmic axes using both self-scaling and predefined
axes.
-
MACHII.C
An example showing how to make filled contours from random input data.
-
ORBITS.C
This example shows how to plot multiple 3-D surfaces and 2-D projections
of the same plot.
-
PIETEST.C
A simple pie chart with a pulled-out sector.
-
POLTEST.C
Polar plot with a logarithmic radial scale.
Polar plot with a linear radial scale.
-
R3TEST.C
This plot illustrates the use of randomly-spaced data points to generate
a 3-D surface plot and contour plot
-
RATES.C
Illustrates the use of a box-and-whiskers plot to display the statistical
spread of data points.
-
SMTEST.C
Smith charts are used for transmission line calculations.
-
TRITEST.C
Triangle plots provide for the graphic display of an attribute
of a three-component mixture.
-
TZTEST.C
This example shows three ways of presenting the data from aircraft
flying over the U.S. during one hour..
-
VFIELD.C
This program illustrates the use of the vector() function to
display a vector field.