Version 3.0.2
matplotlib
Fork me on GitHub

Table of Contents

mpl_toolkits.axisartist.axis_artist

axis_artist.py module provides axis-related artists. They are

  • axis line
  • tick lines
  • tick labels
  • axis label
  • grid lines

The main artist class is a AxisArtist and a GridlinesCollection. The GridlinesCollection is responsible for drawing grid lines and the AxisArtist is responsible for all other artists. The AxisArtist class has attributes that are associated with each type of artists.

  • line : axis line
  • major_ticks : major tick lines
  • major_ticklabels : major tick labels
  • minor_ticks : minor tick lines
  • minor_ticklabels : minor tick labels
  • label : axis label

Typically, the AxisArtist associated with a axes will be accessed with the axis dictionary of the axes, i.e., the AxisArtist for the bottom axis is

ax.axis["bottom"]

where ax is an instance of axes (mpl_toolkits.axislines.Axes). Thus, ax.axis["bottom"].line is an artist associated with the axis line, and ax.axis["bottom"].major_ticks is an artist associated with the major tick lines.

You can change the colors, fonts, line widths, etc. of these artists by calling suitable set method. For example, to change the color of the major ticks of the bottom axis to red,

ax.axis["bottom"].major_ticks.set_color("r")

However, things like the locations of ticks, and their ticklabels need to be changed from the side of the grid_helper.

axis_direction

AxisArtist, AxisLabel, TickLabels have axis_direction attribute, which adjusts the location, angle, etc.,. The axis_direction must be one of [left, right, bottom, top] and they follow the matplotlib convention for the rectangle axis.

For example, for the bottom axis (the left and right is relative to the direction of the increasing coordinate),

  • ticklabels and axislabel are on the right
  • ticklabels and axislabel have text angle of 0
  • ticklabels are baseline, center-aligned
  • axislabel is top, center-aligned

The text angles are actually relative to (90 + angle of the direction to the ticklabel), which gives 0 for bottom axis.

Parameter left bottom right top ticklabels location left right right left axislabel location left right right left ticklabels angle 90 0 -90 180 axislabel angle 180 0 0 180 ticklabel va center baseline center baseline axislabel va center top center bottom ticklabel ha right center right center axislabel ha right center right center

Ticks are by default direct opposite side of the ticklabels. To make ticks to the same side of the ticklabels,

ax.axis["bottom"].major_ticks.set_ticks_out(True)

Following attributes can be customized (use set_xxx method)

  • Ticks : ticksize, tick_out
  • TickLabels : pad
  • AxisLabel : pad

Classes

AttributeCopier(ref_artist[, klass])
AxisArtist(axes, helper[, offset, ...]) An artist which draws axis (a line along which the n-th axes coord is constant) line, ticks, ticklabels, and axis label.
AxisLabel(*args[, axis_direction, axis]) Axis Label.
BezierPath(path, *kl, **kw)
GridlinesCollection(*args[, which, axis]) which : "major" or "minor" axis : "both", "x" or "y"
LabelBase(*kl, **kwargs) A base class for AxisLabel and TickLabels.
TickLabels(*[, axis_direction]) Tick Labels.
Ticks(ticksize[, tick_out, axis]) Ticks are derived from Line2D, and note that ticks themselves are markers.