AxisItem — pyqtgraph 0.9.8 documentation

### Navigation

- index
- modules |
- next |
- previous |
- pyqtgraph 0.9.8 documentation »
- API Reference »
- Pyqtgraph’s Graphics Items »

# AxisItem

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

  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)

    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)

    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)

    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)

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

  `linkedView`()

    Return the ViewBox this axis is linked to

  `setGrid`(grid)

    Set the alpha value for the grid, or False to disable.

  `setHeight`(h=None)

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

  `setLabel`(text=None, units=None, unitPrefix=None, **args)

    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)

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

    Set the pen used for drawing text, axes, ticks, and grid lines. if pen == None, the default will be used (see `setConfigOption`)

  `setRange`(mn, mx)

    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)

    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.

  `setTicks`(ticks)

    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)

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

  `showLabel`(show=True)

    Show/hide the label text for this axis.

  `tickSpacing`(minVal, maxVal, size)

    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)

    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)

    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.

### Navigation

- index
- modules |
- next |
- previous |
- pyqtgraph 0.9.8 documentation »
- API Reference »
- Pyqtgraph’s Graphics Items »