AxisItem

class pyqtgraph.AxisItem(orientation, pen=None, linkView=None, parent=None, maxTickLength=-5, showValues=True)[source]

GraphicsItem showing a single plot axis with ticks, values, and label. Can be configured to fit on any side of a plot, and can automatically synchronize its displayed scale with ViewBox items. Ticks can be extended to draw a grid. If maxTickLength is negative, ticks point into the plot.

__init__(orientation, pen=None, linkView=None, parent=None, maxTickLength=-5, showValues=True)[source]
Arguments:  
orientation one of ‘left’, ‘right’, ‘top’, or ‘bottom’
maxTickLength (px) maximum length of ticks to draw. Negative values draw into the plot, positive values draw outward.
linkView (ViewBox) causes the range of values displayed in the axis to be linked to the visible range of a ViewBox.
showValues (bool) Whether to display values adjacent to ticks
pen (QPen) Pen used when drawing ticks.
enableAutoSIPrefix(enable=True)[source]

Enable (or disable) automatic SI prefix scaling on this axis.

When enabled, this feature automatically determines the best SI prefix to prepend to the label units, while ensuring that axis values are scaled accordingly.

For example, if the axis spans values from -0.1 to 0.1 and has units set to ‘V’ then the axis would display values -100 to 100 and the units would appear as ‘mV’

This feature is enabled by default, and is only available when a suffix (unit string) is provided to display on the label.

generateDrawSpecs(p)[source]

Calls tickValues() and tickStrings() to determine where and how ticks should be drawn, then generates from this a set of drawing commands to be interpreted by drawPicture().

linkToView(view)[source]

Link this axis to a ViewBox, causing its displayed range to match the visible range of the view.

linkedView()[source]

Return the ViewBox this axis is linked to

setGrid(grid)[source]

Set the alpha value (0-255) for the grid, or False to disable.

When grid lines are enabled, the axis tick lines are extended to cover the extent of the linked ViewBox, if any.

setHeight(h=None)[source]

Set the height of this axis reserved for ticks and tick labels. The height of the axis label is automatically added.

If height is None, then the value will be determined automatically based on the size of the tick text.

setLabel(text=None, units=None, unitPrefix=None, **args)[source]

Set the text displayed adjacent to the axis.

Arguments:  
text The text (excluding units) to display on the label for this axis.
units The units for this axis. Units should generally be given without any scaling prefix (eg, ‘V’ instead of ‘mV’). The scaling prefix will be automatically prepended based on the range of data displayed.
**args All extra keyword arguments become CSS style options for the <span> tag which will surround the axis label and units.

The final text generated for the label will look like:

<span style="...options...">{text} (prefix{units})</span>

Each extra keyword argument will become a CSS option in the above template. For example, you can set the font size and color of the label:

labelStyle = {'color': '#FFF', 'font-size': '14pt'}
axis.setLabel('label text', units='V', **labelStyle)
setLogMode(log)[source]

If log is True, then ticks are displayed on a logarithmic scale and values are adjusted accordingly. (This is usually accessed by changing the log mode of a PlotItem)

setPen(*args, **kwargs)[source]

Set the pen used for drawing text, axes, ticks, and grid lines. If no arguments are given, the default foreground color will be used (see setConfigOption).

setRange(mn, mx)[source]

Set the range of values displayed by the axis. Usually this is handled automatically by linking the axis to a ViewBox with linkToView

setScale(scale=None)[source]

Set the value scaling for this axis.

Setting this value causes the axis to draw ticks and tick labels as if the view coordinate system were scaled. By default, the axis scaling is 1.0.

setStyle(**kwds)[source]

Set various style options.

Keyword Arguments:  
tickLength (int) The maximum length of ticks in pixels. Positive values point toward the text; negative values point away.
tickTextOffset (int) reserved spacing between text and axis in px
tickTextWidth (int) Horizontal space reserved for tick text in px
tickTextHeight (int) Vertical space reserved for tick text in px
autoExpandTextSpace (bool) Automatically expand text space if the tick strings become too long.
tickFont (QFont or None) Determines the font used for tick values. Use None for the default font.
stopAxisAtTick (tuple: (bool min, bool max)) If True, the axis line is drawn only as far as the last tick. Otherwise, the line is drawn to the edge of the AxisItem boundary.
textFillLimits

(list of (tick #, % fill) tuples). This structure determines how the AxisItem decides how many ticks should have text appear next to them. Each tuple in the list specifies what fraction of the axis length may be occupied by text, given the number of ticks that already have text displayed. For example:

[(0, 0.8), # Never fill more than 80% of the axis
 (2, 0.6), # If we already have 2 ticks with text,
           # fill no more than 60% of the axis
 (4, 0.4), # If we already have 4 ticks with text,
           # fill no more than 40% of the axis
 (6, 0.2)] # If we already have 6 ticks with text,
           # fill no more than 20% of the axis
showValues (bool) indicates whether text is displayed adjacent to ticks.

Added in version 0.9.9

setTickSpacing(major=None, minor=None, levels=None)[source]

Explicitly determine the spacing of major and minor ticks. This overrides the default behavior of the tickSpacing method, and disables the effect of setTicks(). Arguments may be either major and minor, or levels which is a list of (spacing, offset) tuples for each tick level desired.

If no arguments are given, then the default behavior of tickSpacing is enabled.

Examples:

# two levels, all offsets = 0
axis.setTickSpacing(5, 1)
# three levels, all offsets = 0
axis.setTickSpacing([(3, 0), (1, 0), (0.25, 0)])
# reset to default
axis.setTickSpacing()
setTicks(ticks)[source]

Explicitly determine which ticks to display. This overrides the behavior specified by tickSpacing(), tickValues(), and tickStrings() The format for ticks looks like:

[
    [ (majorTickValue1, majorTickString1), (majorTickValue2, majorTickString2), ... ],
    [ (minorTickValue1, minorTickString1), (minorTickValue2, minorTickString2), ... ],
    ...
]

If ticks is None, then the default tick system will be used instead.

setWidth(w=None)[source]

Set the width of this axis reserved for ticks and tick labels. The width of the axis label is automatically added.

If width is None, then the value will be determined automatically based on the size of the tick text.

showLabel(show=True)[source]

Show/hide the label text for this axis.

tickSpacing(minVal, maxVal, size)[source]

Return values describing the desired spacing and offset of ticks.

This method is called whenever the axis needs to be redrawn and is a good method to override in subclasses that require control over tick locations.

The return value must be a list of tuples, one for each set of ticks:

[
    (major tick spacing, offset),
    (minor tick spacing, offset),
    (sub-minor tick spacing, offset),
    ...
]
tickStrings(values, scale, spacing)[source]

Return the strings that should be placed next to ticks. This method is called when redrawing the axis and is a good method to override in subclasses. The method is called with a list of tick values, a scaling factor (see below), and the spacing between ticks (this is required since, in some instances, there may be only one tick and thus no other way to determine the tick spacing)

The scale argument is used when the axis label is displaying units which may have an SI scaling prefix. When determining the text to display, use value*scale to correctly account for this prefix. For example, if the axis label’s units are set to ‘V’, then a tick value of 0.001 might be accompanied by a scale value of 1000. This indicates that the label is displaying ‘mV’, and thus the tick should display 0.001 * 1000 = 1.

tickValues(minVal, maxVal, size)[source]

Return the values and spacing of ticks to draw:

[  
    (spacing, [major ticks]), 
    (spacing, [minor ticks]), 
    ... 
]

By default, this method calls tickSpacing to determine the correct tick locations. This is a good method to override in subclasses.