SciPlot Widget Programmer's Reference


Viewing this document

This programmer's reference for the SciPlot widget uses HTML3 tables, support for which is becoming very common among WWW browsers. Both Netscape and Mosaic (the most common browsers) support tables, and support for tables in Chimera (my browser of choice) will be included in version 2.0.


Usage

To use the SciPlot widget in an application, include the three source code files SciPlot.c, SciPlot.h, and SciPlotP.h with the rest of the source code for the application. Include the object SciPlot.o in the Makefile rule that compiles the application.

If it is important for the widget to respond to Motif keyboard traversal or any events while in a Motif program, define the keyword "MOTIF" for the C compiler. In a Makefile, a commom place to put this definition is in a variable called "DEFINES". The line in the Makefile would look like this:

DEFINES=-DMOTIF

In source code that uses the SciPlot widget, include the following two header files before references to the plot widget:

#include <X11/Intrinsic.h>
#include "SciPlot.h"

To create the SciPlot widget, use the following code as an example:

plotWidget=XtVaCreateManagedWidget("plot2",
sciplotWidgetClass,parent,
XtNheight, 250,
XtNwidth, 250,
XtNplotTitle, "Demo of Plot Widget",
XtNxLabel, "X Axis (units)",
XtNyLabel, "Y Axis (units)",
XtNchartType, XtPOLAR,
XtNdegrees, True,
NULL);

This example creates a 250x250 polar plot widget as a child of parent, using degrees as the angle measurement unit.

Data is plotted on the graph in groups called lists. Each list consists of a group of coordinates that will be connected together by a drawn line, and share the same point style, point color, line style, line color and legend label. Data is added to the widget using convenience functions only. There is no current provision to add data via the argument list.

An example using one of the convenience functions is given below:

double rlist[]={14.,18.,22.,26.,SCIPLOT_SKIP_VAL,30.,34.,38.,42.};
double tlist[]={30.,60.,90.,120.,SCIPLOT_SKIP_VAL,150.,180.,270.,355.};
int line1;

line1=SciPlotListCreateFromDouble(plotWidget,
9,rlist,tlist,
"List 1");

The variable line1 is the identifier of the list that will be needed to modify the list by the other convenience functions that operate on lists.

This example adds a list to be plotted in plotWidget. If plotWidget was created using the call to XtVaCreateManagedWidget above, the line would be added to a polar plot, where the angles in tlist would be interpreted as degrees.

Note that this example includes the new feature of skipping over a blank space in the line. There will not be a line segment connecting the point (26,120) to (30,150).

There are other convenience functions to specify colors and styles of the points and lines drawn in the Plot widget, as well as functions to pick the colors used and others to update previously defined lists. See Public Functions below for descriptions of all of the convenience functions.


Color

The SciPlot widget fully supports color on displays which also support color. By default, two colors are allocated at creation time: black for the foreground, and white for the background. For the SciPlot widget to use any other color, one of the color convenience functions must be used to allocate a color in the global colormap.

Colors are indicated by an integer returned from the color allocation convenience functions. The two default colors occupy the first two spaces in the color table, where the default background (white) is number 0, and the default foreground (black) is number 1.


Fonts

Fonts used by the SciPlot widget are referenced using special notation. This non-standard notation was used to be able to easily convert between PostScript and X11 notation, and as a result, only a subset of the fonts that are available in both X11 and PostScript are available.

Fonts are referenced by using predefined keywords to indicate the typeface, style, and point size. Each keyword is an integer value defined in SciPlot.h, and a complete font definition is created by logically or-ing keywords together.

Supported fonts and styles are listed below:
Font NameDescription
XtFONT_TIMESTimes
XtFONT_COURIERCourier (monospaced font)
XtFONT_HELVETICAHelvetica
XtFONT_LUCIDALucida
XtFONT_LUCIDASANSLucida Sans Serif
XtFONT_NCSCHOOLBOOKNew Century Schoolbook
Style NameDescription
XtFONT_BOLDBold
XtFONT_ITALICItalic
XtFONT_BOLD_ITALICBold and Italic

A font is specified by logically or-ing together these keywords, plus the size in points.

Some examples follow:

12 point Times, bold:
XtFONT_TIMES|XtFONT_BOLD|12
10 point Courier:
XtFONT_COURIER|10
16 point Lucida, bold and italic:
XtFONT_LUCIDA|XtFONT_BOLD_ITALIC|16

Note that XtFONT_BOLD_ITALIC is simply shorthand for XtFONT_BOLD|XtFONT_ITALIC


Point Styles

The SciPlot widget is capable of drawing markers at each data point. There are 19 predefined point marker definitions:
Style NameDescription
XtMARKER_NONEno point marker drawn
XtMARKER_CIRCLEopen circle
XtMARKER_SQUAREsquare
XtMARKER_UTRIANGLEtriangle (pointing up)
XtMARKER_DTRIANGLEtriangle (pointing down)
XtMARKER_LTRIANGLEtriangle (pointing left)
XtMARKER_RTRIANGLEtriangle (pointing right)
XtMARKER_DIAMONDdiamond
XtMARKER_HOURGLASShourglass shape
XtMARKER_BOWTIEbowtie shape
XtMARKER_FCIRCLEfilled variants of the above...
XtMARKER_FSQUARE
XtMARKER_FUTRIANGLE
XtMARKER_FDTRIANGLE
XtMARKER_FLTRIANGLE
XtMARKER_FRTRIANGLE
XtMARKER_FDIAMOND
XtMARKER_FHOURGLASS
XtMARKER_FBOWTIE


Line Styles

For each list in the SciPlot widget, one of the following styles may be used to draw the lines that connect each point in the list:
Style NameDescription
XtLINE_NONEno line (only points drawn)
XtLINE_SOLIDsolid line (the default)
XtLINE_DOTTEDdotted line
XtLINE_WIDEDOTwidely spaced dotted line


Postscript Output

Encapsulated PostScript (EPS) files of the plot displayed in the SciPlot widget may be generated. These files are suitable for printing or importing into documents that can handle the EPS format. Color is ignored when creating the EPS files, however.


New Resources

Resources for the SciPlot widget are documented below, also showing the default values.
NameClassTypeDefault
XtNaxisFontXtCSciPlotFontintXtFONT_TIMES|10
XtNchartTypeXtCMarginintXtCARTESIAN
XtNdegreesXtCBooleanBooleanTrue
XtNdefaultMarkerSizeXtCIntint3
XtNdrawMajorXtCBooleanBooleanTrue
XtNdrawMajorTicsXtCBooleanBooleanTrue
XtNdrawMinorXtCBooleanBooleanTrue
XtNdrawMinorTicsXtCBooleanBooleanTrue
XtNlabelFontXtCSciPlotFontintXtFONT_TIMES|18
XtNlegendLineSizeXtCMarginint16
XtNlegendMarginXtCMarginint3
XtNmarginXtCMarginint5
XtNmonochromeXtCBooleanBooleanFalse
XtNplotTitleXtCStringString"Plot"
XtNshowLegendXtCBooleanBooleanTrue
XtNshowTitleXtCBooleanBooleanTrue
XtNshowXLabelXtCBooleanBooleanTrue
XtNshowYLabelXtCBooleanBooleanTrue
XtNtitleFontXtCSciPlotFontintXtFONT_HELVETICA|24
XtNtitleMarginXtCMarginint8
XtNxAxisNumbersXtCBooleanBooleanTrue
XtNyAxisNumbersXtCBooleanBooleanTrue
XtNxLabelXtCStringString"X Axis"
XtNyLabelXtCStringString"Y Axis"
XtNxLogXtCBooleanBooleanFalse
XtNyLogXtCBooleanBooleanFalse
XtNyNumbersHorizontalXtCBooleanBooleanTrue
XtNxOriginXtCBooleanBooleanFalse
XtNyOriginXtCBooleanBooleanFalse

XtNchartType
Specifies a the type of chart to be drawn. Currently, two types are available: XtCARTESIAN = cartesian (X-Y) plot, XtPOLAR = polar plot.

XtNdegrees
Sets the type of angular unit measurement: True=degrees, False=radians.

XtNdefaultMarkerSize
Size of the point style markers in pixels.

XtNdrawMajor
Controls the display of major gridlines.

XtNdrawMajorTics
Controls the display of major tic marks on the axes.

XtNdrawMinor
Controls the display of minor gridlines.

XtNdrawMinorTics
Controls the display of minor tic marks on the axes.

XtNlabelFont
Names the font for use on the axis labels, as well as the numbers that mark the scale for each axis.

XtNlegendLineSize
The length (in pixels) of the small lines used to show the line style and color in the legend box.

XtNlegendMargin
Sets the border margin (in pixels) between the legend box outline and anything contained in it. Also controls the spacing between the line sample and the text, and the vertical spacing between legend entries.

XtNmargin
The spacing (in pixels) of the plot with the border of the widget.

XtNmonochrome
Ignores any colors specified in any lists, and draws only in the foreground and background colors of the widget.

XtNplotTitle
This is the title of the plot that is drawn along the lower border of the widget.

XtNshowLegend
If True, the legend block is drawn.

XtNshowTitle
If True, the plot title is drawn.

XtNshowXLabel
If True, the X axis (or the polar axis) label is drawn.

XtNshowYLabel
If True, the Y axis label is drawn.

XtNtitleFont
This font is used for the title of the plot.

XtNtitleMargin
Spacing (in pixels) between the plot and the title.

XtNxLabel
XtNyLabel
(Cartesian only.)
Sets the label for each axis.

XtNxAxisNumbers
XtNyAxisNumbers
(Cartesian only.)
Controls whether the axis numbers are displayed for the corresponding axis. XtNxAxisNumbers also controls the display of the radial numbers in a polar plot.

XtNxLog
XtNyLog
(Cartesian only.)
Controls the logarithmic scales of the X and Y axes. If either of the resources is set to True, the corresponding axis will display in logarithmic units. Note that log axes cannot display numbers less than or equal to zero, so only points with values on that axis greater than zero will be plotted.

XtNyNumbersHorizontal
(Cartesian only.)
If True, then the y axis numbers will be drawn horizontally, somewhat decreasing the area available for showing the plot, but more like a standard scientific plot.


Public Functions

The SciPlot widget uses an abstracted type "real" for its internal representation of floating point values. By default, it is typedeffed to float. Some of the convenience functions may depend on this real data type, but in general, separate functions will be provided depending upon a data type of float or double.

Note that any changes to the widget are not reflected until a call to the public function SciPlotUpdate(). This includes any of the functions that add or remove lists, or change plot styles. Any changes accomplished through XtVaSetValues, however, automatically updates the widget.


Bugs

The font selection algorithm isn't as robust as it should be when trying to choose a replacement for a font; specifically, when the user requests a font or a size that doesn't exist in the X server.

SciPlot : Programmer's Reference | Demo Programs
ListTree : Programmer's Reference

Web Page Design by Rob McMullen
E-mail: rwmcm@mail.ae.utexas.edu
Updated: 4 Sep 96