GradientEditorItem

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

Bases: TickSliderItem

An item that can be used to define a color gradient. Implements common pre-defined gradients that are customizable by the user. :class: GradientWidget <pyqtgraph.GradientWidget> provides a widget with a GradientEditorItem that can be added to a GUI.

Signals:  
sigGradientChanged(self) Signal is emitted anytime the gradient changes. The signal is emitted in real time while ticks are being dragged or colors are being changed.
sigGradientChangeFinished(self) Signal is emitted when the gradient is finished changing.
__init__(*args, **kargs)[source]

Create a new GradientEditorItem. All arguments are passed to TickSliderItem.__init__

Arguments:  
orientation Set the orientation of the gradient. Options are: ‘left’, ‘right’ ‘top’, and ‘bottom’.
allowAdd Default is True. Specifies whether ticks can be added to the item.
tickPen Default is white. Specifies the color of the outline of the ticks. Can be any of the valid arguments for mkPen
addTick(x, color=None, movable=True, finish=True)[source]

Add a tick to the gradient. Return the tick.

Arguments:  
x Position where tick should be added.
color Color of added tick. If color is not specified, the color will be the color of the gradient at the specified position.
movable Specifies whether the tick is movable with the mouse.
colorMap()[source]

Return a ColorMap object representing the current state of the editor.

getColor(x, toQColor=True)[source]

Return a color for a given value.

Arguments:  
x Value (position on gradient) of requested color.
toQColor If true, returns a QColor object, else returns a (r,g,b,a) tuple.
getGradient()[source]

Return a QLinearGradient object.

getLookupTable(nPts, alpha=None)[source]

Return an RGB(A) lookup table (ndarray).

Arguments:  
nPts The number of points in the returned lookup table.
alpha True, False, or None - Specifies whether or not alpha values are included in the table.If alpha is None, alpha will be automatically determined.
isLookupTrivial()[source]

Return True if the gradient has exactly two stops in it: black at 0.0 and white at 1.0

loadPreset(name)[source]

Load a predefined gradient. Currently defined gradients are: odict_keys([‘thermal’, ‘flame’, ‘yellowy’, ‘bipolar’, ‘spectrum’, ‘cyclic’, ‘greyclip’, ‘grey’, ‘viridis’, ‘inferno’, ‘plasma’, ‘magma’])

restoreState(state)[source]

Restore the gradient specified in state.

Arguments:  
state

A dictionary with same structure as those returned by saveState

Keys must include:

  • ‘mode’: hsv or rgb
  • ‘ticks’: a list of tuples (pos, (r,g,b,a))
saveState()[source]

Return a dictionary with parameters for rebuilding the gradient. Keys will include:

  • ‘mode’: hsv or rgb
  • ‘ticks’: a list of tuples (pos, (r,g,b,a))
setColorMode(cm)[source]

Set the color mode for the gradient. Options are: ‘hsv’, ‘rgb’

setOrientation(orientation)[source]

Set the orientation of the GradientEditorItem.

Arguments:  
orientation Options are: ‘left’, ‘right’, ‘top’, ‘bottom’ The orientation option specifies which side of the gradient the ticks are on, as well as whether the gradient is vertical (‘right’ and ‘left’) or horizontal (‘top’ and ‘bottom’).
usesAlpha()[source]

Return True if any ticks have an alpha < 255

TickSliderItem

class pyqtgraph.TickSliderItem(orientation='bottom', allowAdd=True, **kargs)[source]

Bases: GraphicsWidget

A rectangular item with tick marks along its length that can (optionally) be moved by the user.

__init__(orientation='bottom', allowAdd=True, **kargs)[source]
Arguments:  
orientation Set the orientation of the gradient. Options are: ‘left’, ‘right’ ‘top’, and ‘bottom’.
allowAdd Specifies whether ticks can be added to the item by the user.
tickPen Default is white. Specifies the color of the outline of the ticks. Can be any of the valid arguments for mkPen
addTick(x, color=None, movable=True)[source]

Add a tick to the item.

Arguments:  
x Position where tick should be added.
color Color of added tick. If color is not specified, the color will be white.
movable Specifies whether the tick is movable with the mouse.
getTick(tick)[source]

Return the Tick object at the specified index.

Arguments:  
tick An integer corresponding to the index of the desired tick. If the argument is not an integer it will be returned unchanged.
listTicks()[source]

Return a sorted list of all the Tick objects on the slider.

removeTick(tick)[source]

Removes the specified tick.

setOrientation(orientation)[source]

Set the orientation of the TickSliderItem.

Arguments:  
orientation Options are: ‘left’, ‘right’, ‘top’, ‘bottom’ The orientation option specifies which side of the slider the ticks are on, as well as whether the slider is vertical (‘right’ and ‘left’) or horizontal (‘top’ and ‘bottom’).
setTickColor(tick, color)[source]

Set the color of the specified tick.

Arguments:  
tick Can be either an integer corresponding to the index of the tick or a Tick object. Ex: if you had a slider with 3 ticks and you wanted to change the middle tick, the index would be 1.
color The color to make the tick. Can be any argument that is valid for mkBrush
setTickValue(tick, val)[source]

Set the position (along the slider) of the tick.

Arguments:  
tick Can be either an integer corresponding to the index of the tick or a Tick object. Ex: if you had a slider with 3 ticks and you wanted to change the middle tick, the index would be 1.
val The desired position of the tick. If val is < 0, position will be set to 0. If val is > 1, position will be set to 1.
tickValue(tick)[source]

Return the value (from 0.0 to 1.0) of the specified tick.

Arguments:  
tick Can be either an integer corresponding to the index of the tick or a Tick object. Ex: if you had a slider with 3 ticks and you wanted the value of the middle tick, the index would be 1.