Skip to content

Commit 9b5d5bf

Browse files
committed
Add Axes.tick_params and pyplot.tick_params to control tick and tick label appearance.
This allows interactive modification of tick and tick label color, size, etc. svn path=/trunk/matplotlib/; revision=8448
1 parent a6a2844 commit 9b5d5bf

File tree

5 files changed

+282
-53
lines changed

5 files changed

+282
-53
lines changed

CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2010-06-20 Added Axes.tick_params and corresponding pyplot function
2+
to control tick and tick label appearance after an Axes
3+
has been created. - EF
4+
15
2010-06-09 Allow Axes.grid to control minor gridlines; allow
26
Axes.grid and Axis.grid to control major and minor
37
gridlines in the same method call. - EF

boilerplate.py

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def %(func)s(%(argspec)s):
107107
'annotate',
108108
'ticklabel_format',
109109
'locator_params',
110+
'tick_params',
110111
'margins',
111112
)
112113

lib/matplotlib/axes.py

+75
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,81 @@ def locator_params(self, axis='both', tight=None, **kwargs):
21012101
self.yaxis.get_major_locator().set_params(**kwargs)
21022102
self.autoscale_view(tight=tight, scalex=_x, scaley=_y)
21032103

2104+
def tick_params(self, axis='both', **kwargs):
2105+
"""
2106+
Convenience method for changing the appearance of ticks and
2107+
tick labels.
2108+
2109+
Keyword arguments:
2110+
2111+
*axis*
2112+
['x' | 'y' | 'both'] Axis on which to operate;
2113+
default is 'both'.
2114+
2115+
*reset*
2116+
[True | False] If *True*, set all parameters to defaults
2117+
before processing other keyword arguments. Default is
2118+
*False*.
2119+
2120+
*which*
2121+
['major' | 'minor' | 'both'] Default is 'major': apply
2122+
arguments to major ticks only.
2123+
2124+
*direction*
2125+
['in' | 'out'] Puts ticks inside or outside the axes.
2126+
2127+
*length*
2128+
Tick length in points.
2129+
2130+
*width*
2131+
Tick width in points.
2132+
2133+
*color*
2134+
Tick color; accepts any mpl color spec.
2135+
2136+
*pad*
2137+
Distance in points between tick and label.
2138+
2139+
*labelsize*
2140+
Tick label font size in points or as a string (e.g. 'large').
2141+
2142+
*labelcolor*
2143+
Tick label color; mpl color spec.
2144+
2145+
*colors*
2146+
Changes the tick color and the label color to the same value:
2147+
mpl color spec.
2148+
2149+
*zorder*
2150+
Tick and label zorder.
2151+
2152+
*bottom*, *top*, *left*, *right*
2153+
Boolean or ['on' | 'off'], controls whether to draw the
2154+
respective ticks.
2155+
2156+
*labelbottom*, *labeltop*, *labelleft*, *labelright*
2157+
Boolean or ['on' | 'off'], controls whether to draw the
2158+
respective tick labels.
2159+
2160+
Example::
2161+
2162+
ax.tick_params(direction='out', length=6, width=2, colors='r')
2163+
2164+
This will make all major ticks be red, pointing out of the box,
2165+
and with dimensions 6 points by 2 points. Tick labels will
2166+
also be red.
2167+
2168+
"""
2169+
if axis in ['x', 'both']:
2170+
xkw = dict(kwargs)
2171+
xkw.pop('top', None)
2172+
xkw.pop('bottom', None)
2173+
self.xaxis.set_tick_params(**xkw)
2174+
if axis in ['y', 'both']:
2175+
ykw = dict(kwargs)
2176+
ykw.pop('left', None)
2177+
ykw.pop('right', None)
2178+
self.yaxis.set_tick_params(**ykw)
21042179

21052180
def set_axis_off(self):
21062181
"""turn off the axis"""

0 commit comments

Comments
 (0)