32
32
_gridline_param_names = ['grid_' + name
33
33
for name in _line_param_names + _line_param_aliases ]
34
34
35
+ _MARKER_DICT = {
36
+ 'out' : (mlines .TICKDOWN , mlines .TICKUP ),
37
+ 'in' : (mlines .TICKUP , mlines .TICKDOWN ),
38
+ 'inout' : ('|' , '|' ),
39
+ }
40
+
35
41
36
42
class Tick (martist .Artist ):
37
43
"""
@@ -87,11 +93,10 @@ def __init__(
87
93
super ().__init__ ()
88
94
89
95
if gridOn is None :
90
- if major and ( mpl .rcParams ['axes.grid.which' ]
91
- in ('both' , 'major' )):
96
+ which = mpl .rcParams ['axes.grid.which' ]
97
+ if major and ( which in ('both' , 'major' )):
92
98
gridOn = mpl .rcParams ['axes.grid' ]
93
- elif (not major ) and (mpl .rcParams ['axes.grid.which' ]
94
- in ('both' , 'minor' )):
99
+ elif (not major ) and (which in ('both' , 'minor' )):
95
100
gridOn = mpl .rcParams ['axes.grid' ]
96
101
else :
97
102
gridOn = False
@@ -209,7 +214,8 @@ def _apply_tickdir(self, tickdir):
209
214
# further updates ticklabel positions using the new pads.
210
215
if tickdir is None :
211
216
tickdir = mpl .rcParams [f'{ self .__name__ } .direction' ]
212
- _api .check_in_list (['in' , 'out' , 'inout' ], tickdir = tickdir )
217
+ else :
218
+ _api .check_in_list (['in' , 'out' , 'inout' ], tickdir = tickdir )
213
219
self ._tickdir = tickdir
214
220
self ._pad = self ._base_pad + self .get_tick_padding ()
215
221
@@ -436,11 +442,7 @@ def _get_text2_transform(self):
436
442
def _apply_tickdir (self , tickdir ):
437
443
# docstring inherited
438
444
super ()._apply_tickdir (tickdir )
439
- mark1 , mark2 = {
440
- 'out' : (mlines .TICKDOWN , mlines .TICKUP ),
441
- 'in' : (mlines .TICKUP , mlines .TICKDOWN ),
442
- 'inout' : ('|' , '|' ),
443
- }[self ._tickdir ]
445
+ mark1 , mark2 = _MARKER_DICT [self ._tickdir ]
444
446
self .tick1line .set_marker (mark1 )
445
447
self .tick2line .set_marker (mark2 )
446
448
@@ -632,7 +634,7 @@ def __str__(self):
632
634
return "{}({},{})" .format (
633
635
type (self ).__name__ , * self .axes .transAxes .transform ((0 , 0 )))
634
636
635
- def __init__ (self , axes , * , pickradius = 15 ):
637
+ def __init__ (self , axes , * , pickradius = 15 , clear = True ):
636
638
"""
637
639
Parameters
638
640
----------
@@ -641,6 +643,8 @@ def __init__(self, axes, *, pickradius=15):
641
643
pickradius : float
642
644
The acceptance radius for containment tests. See also
643
645
`.Axis.contains`.
646
+ clear : bool, default: True
647
+ Whether to clear the Axis on creation.
644
648
"""
645
649
super ().__init__ ()
646
650
self ._remove_overlapping_locs = True
@@ -674,7 +678,12 @@ def __init__(self, axes, *, pickradius=15):
674
678
self ._major_tick_kw = dict ()
675
679
self ._minor_tick_kw = dict ()
676
680
677
- self .clear ()
681
+ if clear :
682
+ self .clear ()
683
+ else :
684
+ self .converter = None
685
+ self .units = None
686
+
678
687
self ._autoscale_on = True
679
688
680
689
@property
@@ -2353,8 +2362,6 @@ def set_ticks_position(self, position):
2353
2362
can be used if you don't want any ticks. 'none' and 'both'
2354
2363
affect only the ticks, not the labels.
2355
2364
"""
2356
- _api .check_in_list (['top' , 'bottom' , 'both' , 'default' , 'none' ],
2357
- position = position )
2358
2365
if position == 'top' :
2359
2366
self .set_tick_params (which = 'both' , top = True , labeltop = True ,
2360
2367
bottom = False , labelbottom = False )
@@ -2377,7 +2384,8 @@ def set_ticks_position(self, position):
2377
2384
self ._tick_position = 'bottom'
2378
2385
self .offsetText .set_verticalalignment ('top' )
2379
2386
else :
2380
- assert False , "unhandled parameter not caught by _check_in_list"
2387
+ _api .check_in_list (['top' , 'bottom' , 'both' , 'default' , 'none' ],
2388
+ position = position )
2381
2389
self .stale = True
2382
2390
2383
2391
def tick_top (self ):
@@ -2599,8 +2607,6 @@ def set_ticks_position(self, position):
2599
2607
can be used if you don't want any ticks. 'none' and 'both'
2600
2608
affect only the ticks, not the labels.
2601
2609
"""
2602
- _api .check_in_list (['left' , 'right' , 'both' , 'default' , 'none' ],
2603
- position = position )
2604
2610
if position == 'right' :
2605
2611
self .set_tick_params (which = 'both' , right = True , labelright = True ,
2606
2612
left = False , labelleft = False )
@@ -2619,7 +2625,8 @@ def set_ticks_position(self, position):
2619
2625
self .set_tick_params (which = 'both' , right = True , labelright = False ,
2620
2626
left = True , labelleft = True )
2621
2627
else :
2622
- assert False , "unhandled parameter not caught by _check_in_list"
2628
+ _api .check_in_list (['left' , 'right' , 'both' , 'default' , 'none' ],
2629
+ position = position )
2623
2630
self .stale = True
2624
2631
2625
2632
def tick_right (self ):
0 commit comments