This is documentation for Orange 2.7. For the latest documentation, see Orange 3.

Plot (owplot)

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.

Plot layout

show_legend

A boolean controlling whether the legend is displayed or not

show_main_title

Controls whether or not the main plot title is displayed

main_title

The plot title, usually show on top of the plot

set_main_title(t)

Sets the main title to t

set_show_main_title(b)

Shows the main title if b is True, and hides it otherwise.

axis_margin

How much space (in pixels) should be left on each side for the axis, its label and its title.

title_margin

How much space (in pixels) should be left at the top of the plot for the title, if the title is shown.

See also

attribute show_main_title

plot_margin

How much space (in pixels) should be left at each side of the plot as whitespace.

Coordinate transformation

There are several coordinate systems used by OWPlot:

  • widget coordinates.

    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().

  • data coordinates.

    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.

  • plot coordinates.

    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.

Parameters:
  • 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.
Returns:

The transformed point in scene coordinates

Type :

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.

Parameters:
  • 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 point should be in scene coordinates instead.
Returns:

The transformed point in data coordinates

Return type:

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().

nearest_point(pos)

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
point_at(pos)

If there is a point with data coordinates equal to pos, if is returned. Otherwise, this function returns None.

Parameters:pos (tuple of float float) – The position in data 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.

Parameters:
  • 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.

Note

This function does not add items to the legend automatically. You will have to add them yourself with OWLegend.add_item().

See also

OWMultiCurve, OWPoint

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)

Adds a custom PlotItem curve to the plot. If enableLegend is True, a curve symbol defined by OWCurve.point_item() and the curve‘s name OWCurve.name is added to the legend.

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)
add_item(item)

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.

plot_items()

Returns the list of all plot items added to this graph with add_item() or PlotItem.attach().

Axes

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.

Parameters:
  • labels (A list of strings) – The ID of the axis to change
  • labels – The list of labels to be displayed along the axis

Note

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.

Note

This changes the axis scale and removes any previous labels set with set_axis_labels().

Settings

gui

An OWPlotGUI object associated with this graph

Point Selection and Marking

There are four possible selection behaviors used for selecting or marking points in OWPlot. They are used in select_points() and mark_points() and are the same for both operations.

AddSelection

The points are added to the selection, without affected the currently selected points

RemoveSelection

The points are removed from the selection, without affected the currently selected points

ToggleSelection

The points’ selection state is toggled

ReplaceSelection

The current selection is replaced with the new one

Note

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

Parameters:
unselect_all_points()
unmark_all_points()

Unselects or unmarks all the points in the plot

selected_points()
marked_points()

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.

Parameters:
  • xData (list of float) – The list of x coordinates
  • yData (list of float) – The list of y coordinates
Return type:

list of int

Color schemes

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.

theme_name

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()

update_theme()

Updates the current color theme, depending on the value of theme_name.

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

continuous_palette

The palette used when point color represents a continuous attribute

discrete_palette

The palette used when point color represents a discrete attribute