SciPlot Widget Programmer's Reference


Usage

Link against libsciplot and include the header:

#include "SciPlot.h"

The pkg-config name is sciplot (once installed); for an uninstalled build, pass the compiler and linker flags from pkg-config gtk4 cairo pangocairo.

Create the widget and add it to your GTK4 widget hierarchy in the normal way:

GtkWidget *plot = sciplot_widget_new();
gtk_widget_set_size_request(plot, 500, 400);
/* set initial properties */
sciplot_widget_set_plot_title(plot, "Demo of Plot Widget");
sciplot_widget_set_xlabel(plot, "X Axis (units)");
sciplot_widget_set_ylabel(plot, "Y Axis (units)");
sciplot_widget_set_chart_type(plot, XtPOLAR);
sciplot_widget_set_degrees(plot, TRUE);
/* add to parent container */
gtk_box_append(GTK_BOX(box), plot);

Data is plotted in groups called lists. Each list consists of a set of coordinates connected by a line, sharing a point style, point colour, line style, line colour, and legend label. Data is added via convenience functions only.

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 = SciPlotListCreateDouble(plot, 9, rlist, tlist, "List 1");

The SCIPLOT_SKIP_VAL marker causes a break in the line, producing disjoint segments.

Changes are not visible until SciPlotUpdate() is called.


Widget Properties

Properties are set and retrieved with explicit functions of the form sciplot_widget_set_name() and sciplot_widget_get_name(). The defaults match the original Xt resource defaults.
Set functionGet functionTypeDefault
sciplot_widget_set_axis_fontint (font flags)XtFONT_TIMES|10
sciplot_widget_set_chart_typeintXtCARTESIAN
sciplot_widget_set_degreesgbooleanTRUE
sciplot_widget_set_draw_majorsciplot_widget_get_draw_majorgbooleanTRUE
sciplot_widget_set_draw_major_ticsgbooleanTRUE
sciplot_widget_set_draw_minorsciplot_widget_get_draw_minorgbooleanTRUE
sciplot_widget_set_draw_minor_ticsgbooleanTRUE
sciplot_widget_set_label_fontint (font flags)XtFONT_TIMES|18
sciplot_widget_set_legend_through_plotgbooleanFALSE
sciplot_widget_set_marginint (pixels)5
sciplot_widget_set_monochromegbooleanFALSE
sciplot_widget_set_plot_titlesciplot_widget_get_plot_titleconst char *"Plot"
sciplot_widget_set_show_legendsciplot_widget_get_show_legendgbooleanTRUE
sciplot_widget_set_show_titlesciplot_widget_get_show_titlegbooleanTRUE
sciplot_widget_set_show_xlabelsciplot_widget_get_show_xlabelgbooleanTRUE
sciplot_widget_set_show_ylabelsciplot_widget_get_show_ylabelgbooleanTRUE
sciplot_widget_set_title_fontint (font flags)XtFONT_HELVETICA|24
sciplot_widget_set_title_marginint (pixels)16
sciplot_widget_set_xaxis_numberssciplot_widget_get_xaxis_numbersgbooleanTRUE
sciplot_widget_set_xlabelsciplot_widget_get_xlabelconst char *"X Axis"
sciplot_widget_set_xlogsciplot_widget_get_xloggbooleanFALSE
sciplot_widget_set_xoriginsciplot_widget_get_xorigingbooleanFALSE
sciplot_widget_set_yaxis_numberssciplot_widget_get_yaxis_numbersgbooleanTRUE
sciplot_widget_set_ylabelsciplot_widget_get_ylabelconst char *"Y Axis"
sciplot_widget_set_ylogsciplot_widget_get_yloggbooleanFALSE
sciplot_widget_set_y_numbers_horizontalgbooleanTRUE
sciplot_widget_set_yoriginsciplot_widget_get_yorigingbooleanFALSE

chart_type
XtCARTESIAN (x/y plot) or XtPOLAR (polar plot).

degrees
Polar angle unit: TRUE = degrees, FALSE = radians.

draw_major / draw_minor
Show major/minor gridlines.

draw_major_tics / draw_minor_tics
Show major/minor tick marks on the axes.

label_font
Font for axis labels and tick-mark numbers (see Fonts).

legend_through_plot
If TRUE, the legend box overlaps the plot area instead of consuming space beside it.

margin
Spacing in pixels between the plot and the widget border.

monochrome
If TRUE, ignores per-list colours and draws everything in the foreground colour.

plot_title
Title string drawn along the bottom of the widget.

show_legend / show_title / show_xlabel / show_ylabel
Toggle visibility of each element.

title_font
Font for the plot title.

title_margin
Spacing in pixels between the plot area and the title.

xaxis_numbers / yaxis_numbers
Show numeric labels on each axis. xaxis_numbers also controls radial labels in polar mode.

xlabel / ylabel
(Cartesian only.) Axis label strings.

xlog / ylog
(Cartesian only.) Logarithmic axis. Points with non-positive values on a log axis are not plotted.

xorigin / yorigin
(Cartesian only.) Force the corresponding axis to pass through zero.

y_numbers_horizontal
(Cartesian only.) If TRUE, Y-axis tick labels are drawn horizontally.


Color

Colors are referenced by integer IDs returned from the allocation functions. Two colours are pre-allocated at widget creation:
IDColour
0white (background)
1black (foreground)

User colours start at index 2. Color names follow the CSS/GDK convention accepted by gdk_rgba_parse() (e.g., "red", "#ff8000", "rgb(0,128,255)").


Fonts

Fonts are specified by logically OR-ing an XtFONT_* family constant with optional style flags and a point size:
ConstantPango family
XtFONT_TIMESTimes New Roman
XtFONT_COURIERCourier New
XtFONT_HELVETICAHelvetica
XtFONT_LUCIDALucida Bright
XtFONT_LUCIDASANSLucida Sans
XtFONT_NCSCHOOLBOOKCentury Schoolbook L
Style constantEffect
XtFONT_BOLDBold weight
XtFONT_ITALICItalic style
XtFONT_BOLD_ITALICBold and italic (= XtFONT_BOLD|XtFONT_ITALIC)

Examples:

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

If a requested font family is not installed, Pango will substitute the nearest available alternative.


Point Styles

ConstantDescription
XtMARKER_NONEno marker
XtMARKER_CIRCLEopen circle
XtMARKER_SQUAREopen square
XtMARKER_UTRIANGLEtriangle pointing up
XtMARKER_DTRIANGLEtriangle pointing down
XtMARKER_LTRIANGLEtriangle pointing left
XtMARKER_RTRIANGLEtriangle pointing right
XtMARKER_DIAMONDdiamond
XtMARKER_HOURGLASShourglass
XtMARKER_BOWTIEbowtie
XtMARKER_FCIRCLEfilled circle
XtMARKER_FSQUAREfilled square
XtMARKER_FUTRIANGLEfilled triangle up
XtMARKER_FDTRIANGLEfilled triangle down
XtMARKER_FLTRIANGLEfilled triangle left
XtMARKER_FRTRIANGLEfilled triangle right
XtMARKER_FDIAMONDfilled diamond
XtMARKER_FHOURGLASSfilled hourglass
XtMARKER_FBOWTIEfilled bowtie
XtMARKER_DOTsmall filled dot


Line Styles

ConstantDescription
XtLINE_NONEno line (points only)
XtLINE_SOLIDsolid line
XtLINE_DOTTEDdotted line
XtLINE_WIDEDOTwidely-spaced dotted line


PostScript Output

EPS output is generated via Cairo's PS surface and faithfully reproduces the on-screen plot including all colours. Both SciPlotPSCreate and SciPlotPSCreateColor produce colour output (the distinction is retained for API compatibility).


Public Functions

All functions take GtkWidget *w as their first argument (the SciPlot widget instance). Changes to data or styles are not visible until SciPlotUpdate() is called.


Known Issues



SciPlot : Programmer's Reference | Demo Programs

Originally by Rob McMullen. GTK4 port by Barak A. Pearlmutter. Updated: 2 Jun 2026