5555axislabel ha right center right center
5656=================== ====== ======== ====== ========
5757
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 ::
6060
61- ax.axis["bottom"].major_ticks.set_tick_out(True)
61+ ax.axis["bottom"].major_ticks.set_tick_direction("in") # or "out", "inout"
6262
6363The following attributes can be customized (use the ``set_xxx`` methods):
6464
65- * `Ticks`: ticksize, tick_out
65+ * `Ticks`: ticksize, tick_direction
6666* `TickLabels`: pad
6767* `AxisLabel`: pad
6868"""
@@ -109,16 +109,16 @@ class Ticks(AttributeCopier, Line2D):
109109 Ticks are derived from `.Line2D`, and note that ticks themselves
110110 are markers. Thus, you should use set_mec, set_mew, etc.
111111
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").
116115 """
117116
117+ locs_angles_labels = _api .deprecated ("3.11" )(property (lambda self : []))
118+
119+ @_api .delete_parameter ("3.11" , "tick_out" , alternative = "tick_direction" )
118120 def __init__ (self , ticksize , tick_out = False , * , axis = None , ** kwargs ):
119121 self ._ticksize = ticksize
120- self .locs_angles_labels = []
121-
122122 self .set_tick_out (tick_out )
123123
124124 self ._axis = axis
@@ -152,13 +152,33 @@ def get_markeredgecolor(self):
152152 def get_markeredgewidth (self ):
153153 return self .get_attribute_from_ref_artist ("markeredgewidth" )
154154
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+
155162 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.
158165
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" )
159172 def get_tick_out (self ):
160173 """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" )
162182
163183 def set_ticksize (self , ticksize ):
164184 """Set length of the ticks in points."""
@@ -171,7 +191,11 @@ def get_ticksize(self):
171191 def set_locs_angles (self , locs_angles ):
172192 self .locs_angles = locs_angles
173193
174- _tickvert_path = Path ([[0. , 0. ], [1. , 0. ]])
194+ _tick_paths = {
195+ "in" : Path ([[0 , 0 ], [+ 1 , 0 ]]),
196+ "inout" : Path ([[- 1 / 2 , 0. ], [+ 1 / 2 , 0 ]]),
197+ "out" : Path ([[- 1 , 0 ], [0 , 0 ]]),
198+ }
175199
176200 def draw (self , renderer ):
177201 if not self .get_visible ():
@@ -183,18 +207,17 @@ def draw(self, renderer):
183207 gc .set_linewidth (self .get_markeredgewidth ())
184208 gc .set_alpha (self ._alpha )
185209
210+ tickvert_path = self ._tick_paths [self ._tick_dir ]
186211 path_trans = self .get_transform ()
187212 marker_transform = (Affine2D ()
188213 .scale (renderer .points_to_pixels (self ._ticksize )))
189- if self .get_tick_out ():
190- marker_transform .rotate_deg (180 )
191214
192215 for loc , angle in self .locs_angles :
193216 locs = path_trans .transform_non_affine (np .array ([loc ]))
194217 if self .axes and not self .axes .viewLim .contains (* locs [0 ]):
195218 continue
196219 renderer .draw_markers (
197- gc , self . _tickvert_path ,
220+ gc , tickvert_path ,
198221 marker_transform + Affine2D ().rotate_deg (angle ),
199222 Path (locs ), path_trans .get_affine ())
200223
@@ -208,8 +231,9 @@ class LabelBase(mtext.Text):
208231 text_ref_angle, and offset_radius attributes.
209232 """
210233
234+ locs_angles_labels = _api .deprecated ("3.11" )(property (lambda self : []))
235+
211236 def __init__ (self , * args , ** kwargs ):
212- self .locs_angles_labels = []
213237 self ._ref_angle = 0
214238 self ._offset_radius = 0.
215239
@@ -867,14 +891,16 @@ def _init_ticks(self, **kwargs):
867891 + self .offset_transform )
868892
869893 self .major_ticks = Ticks (
870- kwargs .get (
894+ ticksize = kwargs .get (
871895 "major_tick_size" ,
872896 mpl .rcParams [f"{ axis_name } tick.major.size" ]),
897+ tick_direction = mpl .rcParams [f"{ axis_name } tick.direction" ],
873898 axis = self .axis , transform = trans )
874899 self .minor_ticks = Ticks (
875- kwargs .get (
900+ ticksize = kwargs .get (
876901 "minor_tick_size" ,
877902 mpl .rcParams [f"{ axis_name } tick.minor.size" ]),
903+ tick_direction = mpl .rcParams [f"{ axis_name } tick.direction" ],
878904 axis = self .axis , transform = trans )
879905
880906 size = mpl .rcParams [f"{ axis_name } tick.labelsize" ]
@@ -926,14 +952,13 @@ def _update_ticks(self, renderer=None):
926952 if renderer is None :
927953 renderer = self .get_figure (root = True )._get_renderer ()
928954
929- dpi_cor = renderer .points_to_pixels (1. )
930- if self .major_ticks .get_visible () and self .major_ticks .get_tick_out ():
931- ticklabel_pad = self .major_ticks ._ticksize * dpi_cor
932- self .major_ticklabels ._external_pad = ticklabel_pad
933- self .minor_ticklabels ._external_pad = ticklabel_pad
934- else :
935- self .major_ticklabels ._external_pad = 0
936- self .minor_ticklabels ._external_pad = 0
955+ self .major_ticklabels ._external_pad = \
956+ self .minor_ticklabels ._external_pad = (
957+ renderer .points_to_pixels (self .major_ticks ._ticksize )
958+ * {"in" : 0 , "inout" : 1 / 2 , "out" : 1 }[
959+ self .major_ticks .get_tick_direction ()]
960+ * self .major_ticks .get_visible () # 0 if invisible.
961+ )
937962
938963 majortick_iter , minortick_iter = \
939964 self ._axis_artist_helper .get_tick_iterators (self .axes )
@@ -1008,13 +1033,18 @@ def _update_label(self, renderer):
10081033 return
10091034
10101035 if self ._ticklabel_add_angle != self ._axislabel_add_angle :
1011- if ((self .major_ticks .get_visible ()
1012- and not self .major_ticks .get_tick_out ())
1013- or (self .minor_ticks .get_visible ()
1014- and not self .major_ticks .get_tick_out ())):
1015- axislabel_pad = self .major_ticks ._ticksize
1016- else :
1017- axislabel_pad = 0
1036+ axislabel_pad = max (
1037+ # major pad:
1038+ self .major_ticks ._ticksize
1039+ * {"in" : 1 , "inout" : 1 / 2 , "out" : 0 }[
1040+ self .major_ticks .get_tick_direction ()]
1041+ * self .major_ticks .get_visible (), # 0 if invisible.
1042+ # minor pad:
1043+ self .minor_ticks ._ticksize
1044+ * {"in" : 1 , "inout" : 1 / 2 , "out" : 0 }[
1045+ self .minor_ticks .get_tick_direction ()]
1046+ * self .minor_ticks .get_visible (), # 0 if invisible.
1047+ )
10181048 else :
10191049 axislabel_pad = max (self .major_ticklabels ._axislabel_pad ,
10201050 self .minor_ticklabels ._axislabel_pad )
0 commit comments