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 ``rcParams["xtick.direction"]`` and
59
+ ``rcParams["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,28 @@ 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
163
"""Set whether ticks are drawn inside or outside the axes."""
157
- self ._tick_out = b
164
+ self ._tick_dir = "out" if b else "in"
158
165
166
+ @_api .deprecated ("3.11" , alternative = "get_tick_direction" )
159
167
def get_tick_out (self ):
160
168
"""Return whether ticks are drawn inside or outside the axes."""
161
- return self ._tick_out
169
+ if self ._tick_dir == "in" :
170
+ return False
171
+ elif self ._tick_dir == "out" :
172
+ return True
173
+ else :
174
+ raise ValueError (
175
+ f"Tick direction ({ self ._tick_dir !r} ) not supported by get_tick_dir, "
176
+ f"use get_tick_direction instead" )
162
177
163
178
def set_ticksize (self , ticksize ):
164
179
"""Set length of the ticks in points."""
@@ -171,8 +186,6 @@ def get_ticksize(self):
171
186
def set_locs_angles (self , locs_angles ):
172
187
self .locs_angles = locs_angles
173
188
174
- _tickvert_path = Path ([[0. , 0. ], [1. , 0. ]])
175
-
176
189
def draw (self , renderer ):
177
190
if not self .get_visible ():
178
191
return
@@ -182,18 +195,20 @@ def draw(self, renderer):
182
195
gc .set_linewidth (self .get_markeredgewidth ())
183
196
gc .set_alpha (self ._alpha )
184
197
198
+ tickvert_path = (
199
+ Path ([[0 , 0 ], [1 , 0 ]]) if self ._tick_dir == "in" else
200
+ Path ([[- 1 , 0 ], [0 , 0 ]]) if self ._tick_dir == "out" else
201
+ Path ([[- .5 , 0. ], [.5 , 0 ]])) # if self._tick_dir == "inout"
185
202
path_trans = self .get_transform ()
186
203
marker_transform = (Affine2D ()
187
204
.scale (renderer .points_to_pixels (self ._ticksize )))
188
- if self .get_tick_out ():
189
- marker_transform .rotate_deg (180 )
190
205
191
206
for loc , angle in self .locs_angles :
192
207
locs = path_trans .transform_non_affine (np .array ([loc ]))
193
208
if self .axes and not self .axes .viewLim .contains (* locs [0 ]):
194
209
continue
195
210
renderer .draw_markers (
196
- gc , self . _tickvert_path ,
211
+ gc , tickvert_path ,
197
212
marker_transform + Affine2D ().rotate_deg (angle ),
198
213
Path (locs ), path_trans .get_affine ())
199
214
@@ -207,8 +222,9 @@ class LabelBase(mtext.Text):
207
222
text_ref_angle, and offset_radius attributes.
208
223
"""
209
224
225
+ locs_angles_labels = _api .deprecated ("3.11" )(property (lambda self : []))
226
+
210
227
def __init__ (self , * args , ** kwargs ):
211
- self .locs_angles_labels = []
212
228
self ._ref_angle = 0
213
229
self ._offset_radius = 0.
214
230
@@ -866,14 +882,16 @@ def _init_ticks(self, **kwargs):
866
882
+ self .offset_transform )
867
883
868
884
self .major_ticks = Ticks (
869
- kwargs .get (
885
+ ticksize = kwargs .get (
870
886
"major_tick_size" ,
871
887
mpl .rcParams [f"{ axis_name } tick.major.size" ]),
888
+ tick_direction = mpl .rcParams [f"{ axis_name } tick.direction" ],
872
889
axis = self .axis , transform = trans )
873
890
self .minor_ticks = Ticks (
874
- kwargs .get (
891
+ ticksize = kwargs .get (
875
892
"minor_tick_size" ,
876
893
mpl .rcParams [f"{ axis_name } tick.minor.size" ]),
894
+ tick_direction = mpl .rcParams [f"{ axis_name } tick.direction" ],
877
895
axis = self .axis , transform = trans )
878
896
879
897
size = mpl .rcParams [f"{ axis_name } tick.labelsize" ]
@@ -926,10 +944,17 @@ def _update_ticks(self, renderer=None):
926
944
renderer = self .get_figure (root = True )._get_renderer ()
927
945
928
946
dpi_cor = renderer .points_to_pixels (1. )
929
- if self .major_ticks .get_visible () and self . major_ticks . get_tick_out () :
947
+ if self .major_ticks .get_visible ():
930
948
ticklabel_pad = self .major_ticks ._ticksize * dpi_cor
931
- self .major_ticklabels ._external_pad = ticklabel_pad
932
- self .minor_ticklabels ._external_pad = ticklabel_pad
949
+ if self .major_ticks .get_tick_direction () == "in" :
950
+ self .major_ticklabels ._external_pad = 0
951
+ self .minor_ticklabels ._external_pad = 0
952
+ elif self .major_ticks .get_tick_direction () == "out" :
953
+ self .major_ticklabels ._external_pad = ticklabel_pad
954
+ self .minor_ticklabels ._external_pad = ticklabel_pad
955
+ else : # inout
956
+ self .major_ticklabels ._external_pad = ticklabel_pad / 2
957
+ self .minor_ticklabels ._external_pad = ticklabel_pad / 2
933
958
else :
934
959
self .major_ticklabels ._external_pad = 0
935
960
self .minor_ticklabels ._external_pad = 0
@@ -1007,13 +1032,19 @@ def _update_label(self, renderer):
1007
1032
return
1008
1033
1009
1034
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
1035
+ axislabel_pad = 0
1036
+ if self .major_ticks .get_visible ():
1037
+ axislabel_pad = max (
1038
+ axislabel_pad ,
1039
+ {"in" : 1 , "inout" : .5 , "out" : 0 }[
1040
+ self .major_ticks .get_tick_direction ()]
1041
+ * self .major_ticks ._ticksize )
1042
+ if self .minor_ticks .get_visible ():
1043
+ axislabel_pad = max (
1044
+ axislabel_pad ,
1045
+ {"in" : 1 , "inout" : .5 , "out" : 0 }[
1046
+ self .minor_ticks .get_tick_direction ()]
1047
+ * self .major_ticks ._ticksize )
1017
1048
else :
1018
1049
axislabel_pad = max (self .major_ticklabels ._axislabel_pad ,
1019
1050
self .minor_ticklabels ._axislabel_pad )
0 commit comments