CartesianAxes.format¶
- CartesianAxes.format(*, aspect=None, xloc=None, yloc=None, xspineloc=None, yspineloc=None, xtickloc=None, ytickloc=None, fixticks=False, xlabelloc=None, ylabelloc=None, xticklabelloc=None, yticklabelloc=None, xtickdir=None, ytickdir=None, xgrid=None, ygrid=None, xgridminor=None, ygridminor=None, xtickminor=None, ytickminor=None, xticklabeldir=None, yticklabeldir=None, xtickrange=None, ytickrange=None, xwraprange=None, ywraprange=None, xreverse=None, yreverse=None, xlabel=None, ylabel=None, xlim=None, ylim=None, xmin=None, ymin=None, xmax=None, ymax=None, xscale=None, yscale=None, xrotation=None, yrotation=None, xformatter=None, yformatter=None, xticklabels=None, yticklabels=None, xticks=None, yticks=None, xlocator=None, ylocator=None, xminorticks=None, yminorticks=None, xminorlocator=None, yminorlocator=None, xbounds=None, ybounds=None, xmargin=None, ymargin=None, xcolor=None, ycolor=None, xlinewidth=None, ylinewidth=None, xgridcolor=None, ygridcolor=None, xticklen=None, yticklen=None, xlabel_kw=None, ylabel_kw=None, xscale_kw=None, yscale_kw=None, xlocator_kw=None, ylocator_kw=None, xformatter_kw=None, yformatter_kw=None, xminorlocator_kw=None, yminorlocator_kw=None, patch_kw=None, **kwargs)[source]¶
Modify the x and y axis labels, tick locations, tick labels, axis scales, spine settings, and more. Unknown keyword arguments are passed to
Axes.formatandcontext.- Parameters
aspect ({‘auto’, ‘equal’}, optional) – The aspect ratio mode. See
set_aspectfor details.xlabel, ylabel (str, optional) – The x and y axis labels. Applied with
set_xlabelandset_ylabel.xlabel_kw, ylabel_kw (dict-like, optional) – The x and y axis label settings. Applied with the
updatemethod on theTextinstance. Options include'color','size', and'weight'.xlim, ylim (2-tuple of floats or None, optional) – The x and y axis data limits. Applied with
set_xlimandset_ylim.xmin, ymin (float, optional) – The x and y minimum data limits. Useful if you do not want to set the maximum limits.
xmax, ymax (float, optional) – The x and y maximum data limits. Useful if you do not want to set the minimum limits.
xreverse, yreverse (bool, optional) – Sets whether the x and y axis are oriented in the “reverse” direction. The “normal” direction is increasing to the right for the x axis and to the top for the y axis. The “reverse” direction is increasing to the left for the x axis and to the bottom for the y axis.
xscale, yscale (axis scale spec, optional) – The x and y axis scales. Passed to the
Scaleconstructor. For example,xscale='log'applies logarithmic scaling, andxscale=('cutoff', 0.5, 2)applies a customCutoffScale.xscale_kw, yscale_kw (dict-like, optional) – The x and y axis scale settings. Passed to
Scale.xspineloc, yspineloc ({‘both’, ‘bottom’, ‘top’, ‘left’, ‘right’, ‘neither’, ‘center’, ‘zero’}, optional) – The x and y axis spine locations.
xloc, yloc (optional) – Aliases for
xspineloc,yspineloc.xtickloc, ytickloc ({‘both’, ‘bottom’, ‘top’, ‘left’, ‘right’, ‘neither’}, optional) – Which x and y axis spines should have major and minor tick marks.
xtickminor, ytickminor (bool, optional) – Whether to draw minor ticks on the x and y axes.
xtickdir, ytickdir ({‘out’, ‘in’, ‘inout’}) – Direction that major and minor tick marks point for the x and y axis.
xgrid, ygrid (bool, optional) – Whether to draw major gridlines on the x and y axis. Use
gridto toggle both.xgridminor, ygridminor (bool, optional) – Whether to draw minor gridlines for the x and y axis. Use
gridminorto toggle both.xticklabeldir, yticklabeldir ({‘in’, ‘out’}) – Whether to place x and y axis tick label text inside or outside the axes.
xlocator, ylocator (locator spec, optional) – Used to determine the x and y axis tick mark positions. Passed to the
Locatorconstructor. Can be float, list of float, string, ormatplotlib.ticker.Locatorinstance.xticks, yticks (optional) – Aliases for
xlocator,ylocator.xlocator_kw, ylocator_kw (dict-like, optional) – Keyword arguments passed to the
matplotlib.ticker.Locatorclass.xminorlocator, yminorlocator (optional) – As for
xlocator,ylocator, but for the minor ticks.xminorticks, yminorticks (optional) – Aliases for
xminorlocator,yminorlocator.xminorlocator_kw, yminorlocator_kw – As for
xlocator_kw,ylocator_kw, but for the minor locator.xformatter, yformatter (formatter spec, optional) – Used to determine the x and y axis tick label string format. Passed to the
Formatterconstructor. Can be string, list of strings, ormatplotlib.ticker.Formatterinstance. Use[]or'null'for no ticks.xticklabels, yticklabels (optional) – Aliases for
xformatter,yformatter.xformatter_kw, yformatter_kw (dict-like, optional) – Keyword arguments passed to the
matplotlib.ticker.Formatterclass.xrotation, yrotation (float, optional) – The rotation for x and y axis tick labels. Default is
0for normal axes,rc[‘formatter.timerotation’]=90for time x axes.xtickrange, ytickrange ((float, float), optional) – The x and y axis data ranges within which major tick marks are labelled. For example, the tick range
(-1, 1)with axis range(-5, 5)and a tick interval of 1 will only label the ticks marks at -1, 0, and 1. SeeAutoFormatterfor details.xwraprange, ywraprange ((float, float), optional) – The x and y axis data ranges with which major tick mark values are wrapped. For example, the wrap range
(0, 3)causes the values 0 through 9 to be formatted as 0, 1, 2, 0, 1, 2, 0, 1, 2, 0. SeeAutoFormatterfor details.xmargin, ymargin (float, optional) – The default margin between plotted content and the x and y axis spines. Value is proportional to the width, height of the axes. Use this if you want whitespace between plotted content and the spines, but don’t want to explicitly set
xlimorylim.xbounds, ybounds ((float, float), optional) – The x and y axis data bounds within which to draw the spines. For example, the axis range
(0, 4)with bounds(1, 4)will prevent the spines from meeting at the origin.xcolor, ycolor (color-spec, optional) – Color for the x and y axis spines, ticks, tick labels, and axis labels. Default is
rc.color='black'. Use e.g.ax.format(color='red')to set for both axes.xlinewidth, ylinewidth (color-spec, optional) – Line width for the x and y axis spines and major ticks. Default is
rc.linewidth=0.6. Use e.g.ax.format(linewidth=2)to set for both axes.xgridcolor, ygridcolor (color-spec, optional) – Color for the x and y axis major and minor gridlines. Default is
rc[‘grid.color’]='black'. Use e.g.ax.format(gridcolor='r')to set for both axes.xticklen, yticklen (float or str, optional) – Tick lengths for the x and y axis. Units are interpreted by
units, with “points” as the numeric unit. Default isrc.ticklen.Minor tick lengths are scaled according to
rc[‘tick.lenratio’]=0.5. Use e.g.ax.format(ticklen=1)to set for both axes.fixticks (bool, optional) – Whether to always transform the tick locators to a
FixedLocatorinstance. Default isFalse. If your axis ticks are doing weird things (for example, ticks drawn outside of the axis spine), try setting this toTrue.patch_kw (dict-like, optional) – Keyword arguments used to update the background patch. This can be used e.g. to apply background hatching with
patch_kw={'hatch': 'xxx'}.
- Other Parameters
rc_kw (dict, optional) – Dictionary containing
rcsettings applied to this axes usingcontext.**kwargs – Passed to
Axes.formator passed tocontextand used to update axesrcsettings. For example,abcstyle='A.'modifies therc[‘abc.style’]setting.
Note
If you plot something with a datetime64,
pandas.Timestamp,pandas.DatetimeIndex,datetime.date,datetime.time, ordatetime.datetimearray as the x or y axis coordinate, the axis ticks and tick labels will be automatically formatted as dates.