The wckgraph Module
The wckgraph package is a simple graph library for the WCK toolkit. To display a diagram, first create a GraphWidget widget, and then add graph components to the diagram.
The following example draws a simple line diagram:
graph = wckgraph.GraphWidget(root) data = xdata, ydata graph.add(wckgraph.Axes(data)) graph.add(wckgraph.LineGraph(data))The Axes component calculates a suitable viewport based on the data, and also draws the axis (including labels). The LineGraph component draws a line diagram into that viewport. You can use options to configure the axes and the graph components.
For details, see below.
Module Contents
- _DrawContext(widget, bbox) (class) [#]
-
(Internal) Drawing context.
For more information about this class, see The _DrawContext Class.
- AreaGraph(data, **options) (class) [#]
-
Area plot.
- data
- Input data, given as a tuple of two arrays (xdata, ydata).
- **options
- Plot options.
- brush=
- Brush object.
For more information about this class, see The AreaGraph Class.
- Axes(data=None, **options) (class) [#]
-
Standard axes handling.
- data
- Graph data. If given, the class calculates the extent from the actual graph values. If not given, the extent is taken from the extent option.
- **options
- Axes options.
- extent=
- Graph extent.
- grid=
- Grid pen. If given, this should be a Pen object.
- xaxis=
- Where to draw the x-axis. Can be “bottom” or “none”. Default is “bottom”.
- yaxis=
- Where to draw the y-axis. Can be one of “left”, “right”, “both”, or “none”. Default is “left”.
- xoffset=
- Distance between the x-axis and the graph canvas. Defaults to 0.
- yoffset=
- Distance between the y-axis and the graph canvas. Defaults to 0.
For more information about this class, see The Axes Class.
- BarGraph(data, **options) (class) [#]
-
Simple bar plot.
- data
- Input data, given as a tuple of two arrays (xdata, ydata). Both arrays should have the same length.
- **options
- Plot options.
- brush=
- Brush object to use when filling the bars. Use Brush(None) to draw hollow bars.
- pen=
- Pen object to use for the bar border. Use Pen(None) to draw bars without a border.
- barwidth=
- Relative barwidth. Defaults to 1.0 (100%).
For more information about this class, see The BarGraph Class.
- Brush(color=”yellow”) (class) [#]
-
Brush object.
- color=
- Brush color.
For more information about this class, see The Brush Class.
- GraphWidget(master, **options) (class) [#]
-
Graph widget.
- master
- Parent widget.
- **options
- Widget options.
- background=
- Widget background color.
- font=
- Widget font.
- foreground=
- Widget text color.
- canvasbackground=
- Graph canvas background color. Default is same as the widget background.
- height=
- Widget height (in pixels). Defaults to 600 pixels.
- width=
- Widget width (in pixels). Defaults to 400 pixels.
For more information about this class, see The GraphWidget Class.
- LineGraph(data, **options) (class) [#]
-
Line plot.
- data
- Input data, given as a tuple of two arrays (xdata, ydata). Both arrays should have the same length, and the X array should be monotonically increasing (that is, xdata[i] < xdata[i+1] should be true for the entire array).
- **options
- Plot options.
- pen=
- Pen object to use when drawing the line. Defaults to a thin black line.
- marker=
- Marker object. If omitted, markers are not drawn.
- interpolation=
- Line interpolation method. Can be one of “linear”, “smooth”, “stairs”, “stem” or “step”. Defaults to “linear”.
For more information about this class, see The LineGraph Class.
- Marker(style=”circle”, color=”blue”, border=”black”, size=5) (class) [#]
-
Marker object.
- style=
- Marker style. One of “circle”, “diamond”, “plus”, “square”, or “triangle”. Defaults to “circle”.
- color=
- Marker fill color. Use None to draw just the border.
- border=
- Marker border color.
- size=
- Marker size (radius), in pixels. Defaults to 5.
For more information about this class, see The Marker Class.
- Pen(color=”black”, width=1) (class) [#]
-
Pen object.
- color=
- Pen color.
- width=
- Pen width.
For more information about this class, see The Pen Class.
- ScatterGraph(data, **options) (class) [#]
-
Scatter (X-Y) plot.
- data
- Input data, given as a tuple of two arrays (xdata, ydata). Both arrays should have the same length.
- **options
- Plot options.
- marker=
- Marker object. This should be an instance of the Marker class. If omitted, a default marker style is used.
For more information about this class, see The ScatterGraph Class.
- SimpleGraph(data, **options) (class) [#]
-
Base class for simple graphs.
- data
- Input data, given as a tuple of two arrays (xdata, ydata). Both arrays should have the same length.
- **options
- Plot options.
For more information about this class, see The SimpleGraph Class.
The _DrawContext Class
- _DrawContext(widget, bbox) (class) [#]
-
(Internal) Drawing context. A fully populated instance of this class is passed to the graph components during drawing.
The AreaGraph Class
- AreaGraph(data, **options) (class) [#]
-
Area plot. This is similar to LineGraph, but fills the region beneath the line.
- data
- Input data, given as a tuple of two arrays (xdata, ydata).
- **options
- Plot options.
- brush=
- Brush object.
The Axes Class
- Axes(data=None, **options) (class) [#]
-
Standard axes handling. This element sets up a drawing extent for subsequent elements, and also draws axes to the left and below the graph area.
- data
- Graph data. If given, the class calculates the extent from the actual graph values. If not given, the extent is taken from the extent option.
- **options
- Axes options.
- extent=
- Graph extent.
- grid=
- Grid pen. If given, this should be a Pen object.
- xaxis=
- Where to draw the x-axis. Can be “bottom” or “none”. Default is “bottom”.
- yaxis=
- Where to draw the y-axis. Can be one of “left”, “right”, “both”, or “none”. Default is “left”.
- xoffset=
- Distance between the x-axis and the graph canvas. Defaults to 0.
- yoffset=
- Distance between the y-axis and the graph canvas. Defaults to 0.
- getextent() [#]
-
Gets the current graph extent.
- Returns:
- The graph extent (xmin, ymin, xmax, ymax).
- makeaxis(axis, lo, hi) [#]
-
(Hook) Calculates min and max values for an individual graph axis, and determines where to draw tick marks.
- axis
- Axis type (“x” or “y”).
- lo
- Start of axis.
- hi
- End of axis.
- Returns:
- A tuple containing adjusted start and end positions, plus a list of (value, label) tick specifiers.
- render(context) [#]
-
(Internal) Renders axes.
- context
- Graph drawing context.
- setextent(extent) [#]
-
Sets the graph extent.
- extent
- The new extent (xmin, ymin, xmax, ymax).
- xlabel(x, label) [#]
-
(Hook) Generates label for the X axis.
- x
- X value.
- label
- Suggested label. The default implementation simply returns this label.
- Returns:
- The new label. To suppress the label, return None or an empty string.
- ylabel(y, label) [#]
-
(Hook) Generates label for the Y axis.
- y
- Y value.
- label
- Suggested label. The default implementation simply returns this label.
- Returns:
- The new label. To suppress the label, return None or an empty string.
The BarGraph Class
- BarGraph(data, **options) (class) [#]
-
Simple bar plot.
- data
- Input data, given as a tuple of two arrays (xdata, ydata). Both arrays should have the same length.
- **options
- Plot options.
- brush=
- Brush object to use when filling the bars. Use Brush(None) to draw hollow bars.
- pen=
- Pen object to use for the bar border. Use Pen(None) to draw bars without a border.
- barwidth=
- Relative barwidth. Defaults to 1.0 (100%).
The Brush Class
- Brush(color=”yellow”) (class) [#]
-
Brush object. This class is used to specify fill styles for various drawing operations.
- color=
- Brush color.
The GraphWidget Class
- GraphWidget(master, **options) (class) [#]
-
Graph widget. To display a graph, add an axis component, and one or more graph components.
- master
- Parent widget.
- **options
- Widget options.
- background=
- Widget background color.
- font=
- Widget font.
- foreground=
- Widget text color.
- canvasbackground=
- Graph canvas background color. Default is same as the widget background.
- height=
- Widget height (in pixels). Defaults to 600 pixels.
- width=
- Widget width (in pixels). Defaults to 400 pixels.
- add(layer) [#]
-
Adds a graph component to this widget.
- layer
- Layer component.
- clear() [#]
-
Removes all layers from widget.
The LineGraph Class
- LineGraph(data, **options) (class) [#]
-
Line plot.
- data
- Input data, given as a tuple of two arrays (xdata, ydata). Both arrays should have the same length, and the X array should be monotonically increasing (that is, xdata[i] < xdata[i+1] should be true for the entire array).
- **options
- Plot options.
- pen=
- Pen object to use when drawing the line. Defaults to a thin black line.
- marker=
- Marker object. If omitted, markers are not drawn.
- interpolation=
- Line interpolation method. Can be one of “linear”, “smooth”, “stairs”, “stem” or “step”. Defaults to “linear”.
The Marker Class
- Marker(style=”circle”, color=”blue”, border=”black”, size=5) (class) [#]
-
Marker object. This is used to specify marker styles for various plotting operations.
- style=
- Marker style. One of “circle”, “diamond”, “plus”, “square”, or “triangle”. Defaults to “circle”.
- color=
- Marker fill color. Use None to draw just the border.
- border=
- Marker border color.
- size=
- Marker size (radius), in pixels. Defaults to 5.
- plot(context, xy) [#]
-
Plot markers on a surface.
- context
- Rendering context.
- xy
- Coordinate array.
The Pen Class
- Pen(color=”black”, width=1) (class) [#]
-
Pen object. This class is used to specify pen styles for various drawing operations.
- color=
- Pen color.
- width=
- Pen width.
The ScatterGraph Class
- ScatterGraph(data, **options) (class) [#]
-
Scatter (X-Y) plot.
- data
- Input data, given as a tuple of two arrays (xdata, ydata). Both arrays should have the same length.
- **options
- Plot options.
- marker=
- Marker object. This should be an instance of the Marker class. If omitted, a default marker style is used.
The SimpleGraph Class
- SimpleGraph(data, **options) (class) [#]
-
Base class for simple graphs.
- data
- Input data, given as a tuple of two arrays (xdata, ydata). Both arrays should have the same length.
- **options
- Plot options.
- render(context) [#]
-
(Hook) Render graph in context. The default implementation maps input coordinates to pixel coordinates, relative to the graph canvas, and then calls the render_xy method.
- context
- Rendering context.
- render_xy(context, xy) [#]
-
(Hook) Renders graph in context. Same as render, but the coordinates are given in pixel coordinates.
- context
- Rendering context.
- xy
- Coordinate array.