55
55
axislabel ha right center right center
56
56
=================== ====== ======== ====== ========
57
57
58
- Ticks are by default direct opposite side of the ticklabels. To make ticks to
59
- the same side of the ticklabels, ::
58
+ Tick orientation is controlled by :rc:`xtick.direction` and
59
+ :rc:`ytick.direction`; they can be manually adjusted using ::
60
60
61
- ax.axis["bottom"].major_ticks.set_tick_out(True)
61
+ ax.axis["bottom"].major_ticks.set_tick_direction("in") # or "out", "inout"
62
62
63
63
The following attributes can be customized (use the ``set_xxx`` methods):
64
64
65
- * `Ticks`: ticksize, tick_out
65
+ * `Ticks`: ticksize, tick_direction
66
66
* `TickLabels`: pad
67
67
* `AxisLabel`: pad
68
68
"""
@@ -109,16 +109,16 @@ class Ticks(AttributeCopier, Line2D):
109
109
Ticks are derived from `.Line2D`, and note that ticks themselves
110
110
are markers. Thus, you should use set_mec, set_mew, etc.
111
111
112
- To change the tick size (length), you need to use
113
- `set_ticksize`. To change the direction of the ticks (ticks are
114
- in opposite direction of ticklabels by default), use
115
- ``set_tick_out(False)``
112
+ To change the tick size (length), use `set_ticksize`.
113
+ To change the direction of the ticks, use ``set_tick_direction("in")`` (or
114
+ "out", or "inout").
116
115
"""
117
116
117
+ locs_angles_labels = _api .deprecated ("3.11" )(property (lambda self : []))
118
+
119
+ @_api .delete_parameter ("3.11" , "tick_out" , alternative = "tick_direction" )
118
120
def __init__ (self , ticksize , tick_out = False , * , axis = None , ** kwargs ):
119
121
self ._ticksize = ticksize
120
- self .locs_angles_labels = []
121
-
122
122
self .set_tick_out (tick_out )
123
123
124
124
self ._axis = axis
@@ -152,13 +152,33 @@ def get_markeredgecolor(self):
152
152
def get_markeredgewidth (self ):
153
153
return self .get_attribute_from_ref_artist ("markeredgewidth" )
154
154
155
+ def set_tick_direction (self , direction ):
156
+ _api .check_in_list (["in" , "out" , "inout" ], direction = direction )
157
+ self ._tick_dir = direction
158
+
159
+ def get_tick_direction (self ):
160
+ return self ._tick_dir
161
+
155
162
def set_tick_out (self , b ):
156
- """Set whether ticks are drawn inside or outside the axes."""
157
- self . _tick_out = b
163
+ """
164
+ Set whether ticks are drawn inside or outside the axes.
158
165
166
+ .. admonition:: Discouraged
167
+ Consider using the more general method `.set_tick_direction` instead.
168
+ """
169
+ self ._tick_dir = "out" if b else "in"
170
+
171
+ @_api .deprecated ("3.11" , alternative = "get_tick_direction" )
159
172
def get_tick_out (self ):
160
173
"""Return whether ticks are drawn inside or outside the axes."""
161
- return self ._tick_out
174
+ if self ._tick_dir == "in" :
175
+ return False
176
+ elif self ._tick_dir == "out" :
177
+ return True
178
+ else :
179
+ raise ValueError (
180
+ f"Tick direction ({ self ._tick_dir !r} ) not supported by get_tick_out, "
181
+ f"use get_tick_direction instead" )
162
182
163
183
def set_ticksize (self , ticksize ):
164
184
"""Set length of the ticks in points."""
@@ -171,8 +191,6 @@ def get_ticksize(self):
171
191
def set_locs_angles (self , locs_angles ):
172
192
self .locs_angles = locs_angles
173
193
174
- _tickvert_path = Path ([[0. , 0. ], [1. , 0. ]])
175
-
176
194
def draw (self , renderer ):
177
195
if not self .get_visible ():
178
196
return
@@ -182,18 +200,20 @@ def draw(self, renderer):
182
200
gc .set_linewidth (self .get_markeredgewidth ())
183
201
gc .set_alpha (self ._alpha )
184
202
203
+ tickvert_path = (
204
+ Path ([[0 , 0 ], [1 , 0 ]]) if self ._tick_dir == "in" else
205
+ Path ([[- 1 , 0 ], [0 , 0 ]]) if self ._tick_dir == "out" else
206
+ Path ([[- .5 , 0. ], [.5 , 0 ]])) # if self._tick_dir == "inout"
185
207
path_trans = self .get_transform ()
186
208
marker_transform = (Affine2D ()
187
209
.scale (renderer .points_to_pixels (self ._ticksize )))
188
- if self .get_tick_out ():
189
- marker_transform .rotate_deg (180 )
190
210
191
211
for loc , angle in self .locs_angles :
192
212
locs = path_trans .transform_non_affine (np .array ([loc ]))
193
213
if self .axes and not self .axes .viewLim .contains (* locs [0 ]):
194
214
continue
195
215
renderer .draw_markers (
196
- gc , self . _tickvert_path ,
216
+ gc , tickvert_path ,
197
217
marker_transform + Affine2D ().rotate_deg (angle ),
198
218
Path (locs ), path_trans .get_affine ())
199
219
@@ -207,8 +227,9 @@ class LabelBase(mtext.Text):
207
227
text_ref_angle, and offset_radius attributes.
208
228
"""
209
229
230
+ locs_angles_labels = _api .deprecated ("3.11" )(property (lambda self : []))
231
+
210
232
def __init__ (self , * args , ** kwargs ):
211
- self .locs_angles_labels = []
212
233
self ._ref_angle = 0
213
234
self ._offset_radius = 0.
214
235
@@ -866,14 +887,16 @@ def _init_ticks(self, **kwargs):
866
887
+ self .offset_transform )
867
888
868
889
self .major_ticks = Ticks (
869
- kwargs .get (
890
+ ticksize = kwargs .get (
870
891
"major_tick_size" ,
871
892
mpl .rcParams [f"{ axis_name } tick.major.size" ]),
893
+ tick_direction = mpl .rcParams [f"{ axis_name } tick.direction" ],
872
894
axis = self .axis , transform = trans )
873
895
self .minor_ticks = Ticks (
874
- kwargs .get (
896
+ ticksize = kwargs .get (
875
897
"minor_tick_size" ,
876
898
mpl .rcParams [f"{ axis_name } tick.minor.size" ]),
899
+ tick_direction = mpl .rcParams [f"{ axis_name } tick.direction" ],
877
900
axis = self .axis , transform = trans )
878
901
879
902
size = mpl .rcParams [f"{ axis_name } tick.labelsize" ]
@@ -925,14 +948,13 @@ def _update_ticks(self, renderer=None):
925
948
if renderer is None :
926
949
renderer = self .get_figure (root = True )._get_renderer ()
927
950
928
- dpi_cor = renderer .points_to_pixels (1. )
929
- if self .major_ticks .get_visible () and self .major_ticks .get_tick_out ():
930
- ticklabel_pad = self .major_ticks ._ticksize * dpi_cor
931
- self .major_ticklabels ._external_pad = ticklabel_pad
932
- self .minor_ticklabels ._external_pad = ticklabel_pad
933
- else :
934
- self .major_ticklabels ._external_pad = 0
935
- self .minor_ticklabels ._external_pad = 0
951
+ self .major_ticklabels ._external_pad = \
952
+ self .minor_ticklabels ._external_pad = (
953
+ renderer .points_to_pixels (self .major_ticks ._ticksize )
954
+ * {"in" : 0 , "inout" : 1 / 2 , "out" : 1 }[
955
+ self .major_ticks .get_tick_direction ()]
956
+ * self .major_ticks .get_visible () # 0 if invisible.
957
+ )
936
958
937
959
majortick_iter , minortick_iter = \
938
960
self ._axis_artist_helper .get_tick_iterators (self .axes )
@@ -1007,13 +1029,18 @@ def _update_label(self, renderer):
1007
1029
return
1008
1030
1009
1031
if self ._ticklabel_add_angle != self ._axislabel_add_angle :
1010
- if ((self .major_ticks .get_visible ()
1011
- and not self .major_ticks .get_tick_out ())
1012
- or (self .minor_ticks .get_visible ()
1013
- and not self .major_ticks .get_tick_out ())):
1014
- axislabel_pad = self .major_ticks ._ticksize
1015
- else :
1016
- axislabel_pad = 0
1032
+ axislabel_pad = max (
1033
+ # major pad:
1034
+ self .major_ticks ._ticksize
1035
+ * {"in" : 1 , "inout" : .5 , "out" : 0 }[
1036
+ self .major_ticks .get_tick_direction ()]
1037
+ * self .major_ticks .get_visible (), # 0 if invisible.
1038
+ # minor pad:
1039
+ self .minor_ticks ._ticksize
1040
+ * {"in" : 1 , "inout" : .5 , "out" : 0 }[
1041
+ self .minor_ticks .get_tick_direction ()]
1042
+ * self .minor_ticks .get_visible (), # 0 if invisible.
1043
+ )
1017
1044
else :
1018
1045
axislabel_pad = max (self .major_ticklabels ._axislabel_pad ,
1019
1046
self .minor_ticklabels ._axislabel_pad )
0 commit comments