Curve (owcurve)

class Orange.OrangeWidgets.plot.owcurve.OWPlotItem

This class represents a base for any item than can be added to a plot.

attach(plot)

Attaches this item to plot. The Plot takes the ownership of this item.

Parameters:plot (OWPlot) – the plot to which to add this item
Seealso :OWPlot.add_item().
detach()

Removes this item from its plot. The item’s ownership is returned to Python.

plot()
Returns:The plot this item is attached to. If the item is not attached to any plot, None is returned.
Return type:OWPlot
data_rect()

Returns the bounding rectangle of this item in data coordinates. This method is used in autoscale calculations.

set_data_rect(rect)
Parameters:rect (QRectF) – The new bounding rectangle in data coordinates
set_graph_transform(transform)

Sets the graph transform (the transformation that maps from data to plot coordinates) for this item.

graph_transform()
Returns:The current graph transformation.
Return type:QTransform
set_zoom_transform(transform)

Sets the zoom transform (the transformation that maps from plot to scene coordinates) for this item.

zoom_transform()
Returns:The current zoom transformation.
Return type:QTransform
set_axes(x_axis, y_axis)

Sets the pair of axes used for positioning this item.

axes()
Returns:The item’s pair of axes
Return type:tuple of int int
update_properties()

Called by the plot, this function is supposed to updates the item’s internal state to match its settings.

The default implementation does nothing and shold be reimplemented by subclasses.

register_points()

If this item constains any points (of type OWPoint), add them to the plot in this function.

The default implementation does nothing.

set_in_background(background)

If background is True, the item is moved to be background of this plot, behind other items and axes. Otherwise, it’s brought to the front, in front of axes.

The default in False, so that items apper in front of axes.

is_in_background()

Returns if item is in the background, set with set_in_background().

Subclassing

Often you will want to create a custom curve class that inherits from OWCurve. For this purpose, OWPlotItem provides two virtual methods: paint() and update_properties().

  • update_properties() is called whenever a curve or the plot is changed and needs to be updated. In this method, child items and other members should be recalculated and updated. The OWCurve even provides a number of methods for asynchronous (threaded) updating.
  • paint() is called whenever the item needs to be painted on the scene. This method is called more often, so it’s advisable to avoid long operation in the method.

Most provided plot items, including OWCurve, OWMultiCurve and utility curves in owtools only reimplement the first method, because they are optimized for performance with large data sets.

class Orange.OrangeWidgets.plot.owcurve.OWCurve(xData=[], yData=[], x_axis_key=2, y_axis_key=0, tooltip=None)

This class represents a curve on a plot. It is essentially a plot item with a series of data points or a continuous line.

Parameters:
  • xData (list of float) – list of x coordinates
  • yData (list of float) – list of y coordinates
  • x_axis_key (int) – The x axis of this curve
  • y_axis_key (int) – The y axis of this curve
  • tooltip (str) – The curve’s tooltip

Note

All the points or line segments in an OWCurve have the same properties. Different points in one curve are supported by the OWMultiCurve class.

point_item(x, y, size=0, parent=None)

Returns a single point with this curve’s properties. It is useful for representing the curve, for example in the legend.

Parameters:
  • x (float) – The x coordinate of the point.
  • y (float) – The y coordinate of the point.
  • size (int) – If nonzero, this argument determines the size of the resulting point. Otherwise, the point is created with the curve’s OWCurve.point_size()
  • parent (QGraphicsItem) – An optional parent for the returned item.
name

The name of the curve, used in the legend or in tooltips.

set_data(x_data, y_data)

Sets the curve’s data to a list of coordinates specified by x_data and y_data.

data()
Returns:The curve’s data as a list of data points.
Return type:list of tuple of float float
set_style(style)

Sets the curve’s style to style.

The following values are recognized by OWCurve:

Value Result
OWCurve.Points Only points are shown, no lines
OWCurve.Lines A continuous line is shown, no points
OWCurve.LinesPoints Both points and lines between them are shown
OWCurve.Dots A dotted line is shown, no points
OWCurve.NoCurve Deprecated, same as OWCurve.Points

Curve subclasses can use this value for different drawing modes. Values up to OWCurve.UserCurve are reserved, so use only higher numbers, like the following example:

class MyCurve(OWCurve):
    PonyStyle = OWCurve.UserCurve + 42

    def draw_ponies()
        # Draw type-specific things here

    def update_properties(self):
        if self.style() == PonyStyle:
            self.draw_ponies()
        else:
            OWCurve.update_properties(self)
style()
Returns:The curve’s style, set with set_style()
Return type:int
cancel_all_updates()

Cancel all pending threaded updates and block until they are finished. This is usually called before starting a new round of updates.

update_number_of_items()

Resizes the point list so that it matches the number of data points in data()

update_point_coordinates()

Sets the coordinates of each point to match data().

update_point_positions()

Sets the scene positions of the points to match their data coordinates.

class Orange.OrangeWidgets.plot.owcurve.OWMultiCurve

A multi-curve is a curve in which each point can have its own properties. The point coordinates can be set by calling OWCurve.set_data(), just like in a normal curve.

In addition, OWMultiCurve provides methods for setting properties for individual points. Each of this methods take a list as a parameter. If the list has less elements that the curve’s data, the first element is used for all points.

set_point_colors(lst)
Parameters:lst (list of QColor) – The list of colors to assign to points
set_point_sizes(lst)
Parameters:lst (list of int) – The list of sizes to assign to points
set_point_symbols(lst)
Parameters:lst (list of int) – The list of symbols to assign to points