- class OrangeWidgets.plot.OWPlot(parent=None, name=None, show_legend=1, axes=[2, 0], widget=None)¶
The base class for all plots in Orange. It uses the Qt Graphics View Framework to draw elements on a graph.
A boolean controlling whether the legend is displayed or not
Controls whether or not the main plot title is displayed
The plot title, usually show on top of the plot
Sets the main title to t
Shows the main title if b is True, and hides it otherwise.
How much space (in pixels) should be left on each side for the axis, its label and its title.
How much space (in pixels) should be left at the top of the plot for the title, if the title is shown.
How much space (in pixels) should be left at each side of the plot as whitespace.
There are several coordinate systems used by OWPlot:
This is the coordinate system of the position returned by QEvent.pos(). No calculations or positions is done with this coordinates, they must first be converted to scene coordinates with mapToScene().
The value used internally in Orange to specify the values of attributes. For example, this can be age in years, the number of legs, or any other numeric value.
These coordinates specify where the plot items are placed on the graph, but doesn’t account for zoom. They can be retrieved for a particular plot item with PlotItem.pos().
scene or zoom coordinates.
Like plot coordinates, except that they take the zoom_transform into account. They represent the actual position of an item on the scene.
These are the coordinates returned by PlotItem.scenePos() and mapToScene().
For example, they can be used to determine what is under the cursor.
In most cases, you will use data coordinates for interacting with the actual data, and scene coordinates for interacting with the plot items. The other two sets are mostly used for converting.
- map_to_graph(point, axes=None, zoom=False)¶
Maps point, which can be ether a tuple of (x,y), a QPoint or a QPointF, from data coordinates to plot coordinates.
- point (tuple or QPointF) – The point in data coordinates
- axes (tuple of float float) – The pair of axes along which to transform the point. If none are specified, (xBottom, yLeft) will be used.
- zoom (int) – if True, the current zoom_transform will be considered in the transformation, and the result will be in scene coordinates instead.
The transformed point in scene coordinates
tuple of float float
- map_from_graph(point, axes=None, zoom=False)¶
Maps point, which can be ether a tuple of (x,y), a QPoint or a QPointF, from plot coordinates to data coordinates.
- point (tuple or QPointF) – The point in data coordinates
- zoom (int) – if True, the current zoom_transform will be considered in the transformation, and the point should be in scene coordinates instead.
The transformed point in data coordinates
tuple of float float
- transform(axis_id, value)¶
Transforms the value from data to plot coordinates along the axis axis_id.
This function always ignores zoom. If you need to account for zooming, use map_to_graph().
- inv_transform(axis_id, value)¶
Transforms the value from plot to data coordinates along the axis axis_id.
This function always ignores zoom. If you need to account for zooming, use map_from_graph().
Returns the point nearest to pos, or None if no point is close enough.
Parameters: pos (QPointF) – The position in scene coordinates Return type: OWPoint
- Data curves
The preferred method for showing a series of data points is set_main_curve_data(). It allows you to specify point positions, colors, labels, sizes and shapes.
- set_main_curve_data(x_data, y_data, color_data, label_data, size_data, shape_data, marked_data=, valid_data=, x_axis_key=2, y_axis_key=0)¶
Creates a single curve that can have points of different colors, shapes and sizes. This is the preferred method for visualization that show a series of different points.
- x_data (list of float) – The list of X coordinates of the points
- y_data (list of float) – The list of Y coordinates of the points
- color_data (list of QColor) – The list of point colors
- label_data (list of str) – The list of point labels
- size_data (list of int) – The list of point sizes
- shape_data (list of int) – The list of point symbols
The number of points in the curve will be equal to min(len(x_data), len(y_data)). The other four list can be empty, in which case a default value will be used. If they contain only one element, its value will be used for all points.
This function does not add items to the legend automatically. You will have to add them yourself with OWLegend.add_item().
- add_curve(name, brushColor=None, penColor=None, size=5, style=0, symbol=0, enableLegend=False, xData=, yData=, showFilledSymbols=None, lineWidth=1, pen=None, autoScale=0, antiAlias=None, penAlpha=255, brushAlpha=255, x_axis_key=2, y_axis_key=0)¶
Creates a new OWCurve with the specified parameters and adds it to the graph. If enableLegend is True, a curve symbol is added to the legend.
- add_custom_curve(curve, enableLegend=False)¶
This function recalculates axis bounds and replots the plot if needed.
Parameters: curve (OWCurve) – The curve to add
- add_marker(name, x, y, alignment=-1, bold=0, color=None, brushColor=None, size=None, antiAlias=None, x_axis_key=2, y_axis_key=0)¶
Adds any PlotItem item to this plot. Calling this function directly is useful for adding a Marker or another object that does not have to appear in the legend. For data curves, consider using add_custom_curve() instead.
- add_axis(axis_id, title=, title_above=False, title_location=4, line=None, arrows=0, zoomable=False)¶
Creates an OrangeWidgets.plot.OWAxis with the specified axis_id and title.
- add_custom_axis(axis_id, axis)¶
Adds a custom axis with id axis_id to the plot
- set_axis_enabled(axis, enable)¶
- set_axis_labels(axis_id, labels)¶
Sets the labels of axis axis_id to labels. This is used for axes displaying a discrete data type.
- labels (A list of strings) – The ID of the axis to change
- labels – The list of labels to be displayed along the axis
This changes the axis scale and removes any previous scale set with set_axis_scale().
- set_axis_scale(axis_id, min, max, step_size=0)¶
Sets the scale of axis axis_id to show an interval between min and max. If step is specified and non-zero, it determines the steps between label on the axis. Otherwise, they are calculated automatically.
This changes the axis scale and removes any previous labels set with set_axis_labels().
Point Selection and Marking
The points are added to the selection, without affected the currently selected points
The points are removed from the selection, without affected the currently selected points
The points’ selection state is toggled
The current selection is replaced with the new one
There are exacly the same functions for point selection and marking. For simplicity, they are only documented once.
- select_points(area, behavior)¶
- mark_points(area, behavior)¶
Selects or marks all points inside the area
Unselects or unmarks all the points in the plot
Returns a list of all selected or marked points
Return type: list of OWPoint
- selected_points(xData, yData)
For each of the point specified by xData and yData, the point’s selection state is returned.
- xData (list of float) – The list of x coordinates
- yData (list of float) – The list of y coordinates
list of int
By default, OWPlot uses the application’s system palette for drawing everything except data curves and points. This way, it maintains consistency with other application with regards to the user interface.
If data is plotted with no color specified, it will use a system color as well, so that a good contrast with the background in guaranteed.
OWPlot uses the OWidget.palette() to determine its color scheme, so it can be changed using QWidget.setPalette(). There are also two predefined color schemes: OWPalette.Dark and OWPalette.Light, which provides a dark and a light scheme respectively.
A string attribute with three possible values: ============== =========================== Value Meaning ————– ————————— “default” The system palette is used “dark” The dark theme is used “light” The light theme is used ============== ===========================
To apply the settings, first set this attribute’s value, and then call update_theme()
On the other hand, curves with a specified color will use colors from Orange’s palette, which can be configured within Orange. Each plot contains two separate palettes: one for continuous attributes, and one for discrete ones. Both are created by OWColorPalette.ColorPaletteGenerator
The palette used when point color represents a continuous attribute
The palette used when point color represents a discrete attribute