PlotDataItem

class pyqtgraph.PlotDataItem(*args, **kargs)[source]

Bases: GraphicsObject

GraphicsItem for displaying plot curves, scatter plots, or both. While it is possible to use PlotCurveItem or ScatterPlotItem individually, this class provides a unified interface to both. Instances of PlotDataItem are usually created by plot() methods such as pyqtgraph.plot() and PlotItem.plot().

Signals:

sigPlotChanged(self)

Emitted when the data in this item is updated.

sigClicked(self, ev)

Emitted when the item is clicked.

sigPointsClicked(self, points, ev)

Emitted when a plot point is clicked Sends the list of points under the mouse.

sigPointsHovered(self, points, ev)

Emitted when a plot point is hovered over. Sends the list of points under the mouse.

__init__(*args, **kargs)[source]

There are many different ways to create a PlotDataItem:

Data initialization arguments: (x,y data only)

PlotDataItem(xValues, yValues)

x and y values may be any sequence (including ndarray) of real numbers

PlotDataItem(yValues)

y values only – x will be automatically set to range(len(y))

PlotDataItem(x=xValues, y=yValues)

x and y given by keyword arguments

PlotDataItem(ndarray(Nx2))

numpy array with shape (N, 2) where x=data[:,0] and y=data[:,1]

Data initialization arguments: (x,y data AND may include spot style)

PlotDataItem(recarray)

numpy array with dtype=[('x', float), ('y', float), ...]

PlotDataItem(list-of-dicts)

[{'x': x, 'y': y, ...},   ...]

PlotDataItem(dict-of-lists)

{'x': [...], 'y': [...],  ...}

PlotDataItem(MetaArray)

1D array of Y values with X sepecified as axis values OR 2D array with a column ‘y’ and extra columns as needed.

Line style keyword arguments:

connect

Specifies how / whether vertexes should be connected. See arrayToQPath()

pen

Pen to use for drawing line between points. Default is solid grey, 1px width. Use None to disable line drawing. May be any single argument accepted by mkPen()

shadowPen

Pen for secondary line to draw behind the primary line. disabled by default. May be any single argument accepted by mkPen()

fillLevel

Fill the area between the curve and fillLevel

fillOutline

(bool) If True, an outline surrounding the fillLevel area is drawn.

fillBrush

Fill to use when fillLevel is specified. May be any single argument accepted by mkBrush()

stepMode

(str or None) If “center”, a step is drawn using the x values as boundaries and the given y values are associated to the mid-points between the boundaries of each step. This is commonly used when drawing histograms. Note that in this case, len(x) == len(y) + 1 If “left” or “right”, the step is drawn assuming that the y value is associated to the left or right boundary, respectively. In this case len(x) == len(y) If not passed or an empty string or None is passed, the step mode is not enabled. Passing True is a deprecated equivalent to “center”. (added in version 0.9.9)

Point style keyword arguments: (see ScatterPlotItem.setData() for more information)

symbol

Symbol to use for drawing points OR list of symbols, one per point. Default is no symbol. Options are o, s, t, d, +, or any QPainterPath

symbolPen

Outline pen for drawing points OR list of pens, one per point. May be any single argument accepted by mkPen()

symbolBrush

Brush for filling points OR list of brushes, one per point. May be any single argument accepted by mkBrush()

symbolSize

Diameter of symbols OR list of diameters.

pxMode

(bool) If True, then symbolSize is specified in pixels. If False, then symbolSize is specified in data coordinates.

Optimization keyword arguments:

antialias

(bool) By default, antialiasing is disabled to improve performance. Note that in some cases (in particluar, when pxMode=True), points will be rendered antialiased even if this is set to False.

decimate

deprecated.

downsample

(int) Reduce the number of samples displayed by this value

downsampleMethod

‘subsample’: Downsample by taking the first of N samples. This method is fastest and least accurate. ‘mean’: Downsample by taking the mean of N samples. ‘peak’: Downsample by drawing a saw wave that follows the min and max of the original data. This method produces the best visual representation of the data but is slower.

autoDownsample

(bool) If True, resample the data before plotting to avoid plotting multiple line segments per pixel. This can improve performance when viewing very high-density data, but increases the initial overhead and memory usage.

clipToView

(bool) If True, only plot data that is visible within the X range of the containing ViewBox. This can improve performance when plotting very large data sets where only a fraction of the data is visible at any time.

dynamicRangeLimit

(float or None) Limit off-screen positions of data points at large magnification to avoids display errors. Disabled if None.

skipFiniteCheck

(bool) Optimization parameter that can speed up plot time by telling the painter to not check and compensate for NaN values. If set to True, and NaN values exist, the data may not be displayed or your plot will take a significant performance hit. Defaults to False.

identical

deprecated

Meta-info keyword arguments:

name

name of dataset. This would appear in a legend

dataBounds(ax, frac=1.0, orthoRange=None)[source]

Returns the range occupied by the data (along a specific axis) in this item. This method is called by ViewBox when auto-scaling.

Arguments:

ax

(0 or 1) the axis for which to return this item’s data range

frac

(float 0.0-1.0) Specifies what fraction of the total data range to return. By default, the entire range is returned. This allows the ViewBox to ignore large spikes in the data when auto-scaling.

orthoRange

([min,max] or None) Specifies that only the data within the given range (orthogonal to ax) should me measured when returning the data range. (For example, a ViewBox might ask what is the y-range of all data with x-values between min and max)

dataRect()[source]

Returns a bounding rectangle (as QRectF) for the full set of data. Will return None if there is no data or if all values (x or y) are NaN.

pixelPadding()[source]

Return the size in pixels that this item may draw beyond the values returned by dataBounds(). This method is called by ViewBox when auto-scaling.

setData(*args, **kargs)[source]

Clear any data displayed by this item and display new data. See __init__() for details; it accepts the same arguments.

setDownsampling(ds=None, auto=None, method=None)[source]

Set the downsampling mode of this item. Downsampling reduces the number of samples drawn to increase performance.

Arguments:

ds

(int) Reduce visible plot samples by this factor. To disable, set ds=1.

auto

(bool) If True, automatically pick ds based on visible range

mode

‘subsample’: Downsample by taking the first of N samples. This method is fastest and least accurate. ‘mean’: Downsample by taking the mean of N samples. ‘peak’: Downsample by drawing a saw wave that follows the min and max of the original data. This method produces the best visual representation of the data but is slower.

setDynamicRangeLimit(limit=1000000.0, hysteresis=3.0)[source]

Limit the off-screen positions of data points at large magnification This avoids errors with plots not displaying because their visibility is incorrectly determined. The default setting repositions far-off points to be within +-1E+06 times the viewport height.

Arguments:

limit

(float or None) Any data outside the range of limit * hysteresis will be constrained to the limit value limit. All values are relative to the viewport height. ‘None’ disables the check for a minimal increase in performance. Default is 1E+06.

hysteresis

(float) Hysteresis factor that controls how much change in zoom level (vertical height) is allowed before recalculating Default is 3.0

setLogMode(xMode, yMode)[source]

To enable log scaling for y<0 and y>0, the following formula is used:

scaled = sign(y) * log10(abs(y) + eps)

where eps is the smallest unit of y.dtype. This allows for handling of 0. values, scaling of large values, as well as the typical log scaling of values in the range -1 < x < 1. Note that for values within this range, the signs are inverted.

setPen(*args, **kargs)[source]
Sets the pen used to draw lines between points.
pen can be a QPen or any argument accepted by pyqtgraph.mkPen()
setShadowPen(*args, **kargs)[source]
Sets the shadow pen used to draw lines between points (this is for enhancing contrast or emphacizing data).
This line is drawn behind the primary pen (see setPen()) and should generally be assigned greater width than the primary pen.
pen can be a QPen or any argument accepted by pyqtgraph.mkPen()
viewRangeChanged(vb=None, ranges=None, changed=None)[source]

view range has changed; re-plot if needed