28
28
29
29
GRIDLINE_INTERPOLATION_STEPS = 180
30
30
31
- # This list is being used for compatibility with Axes.grid, which
32
- # allows all Line2D kwargs.
33
- _line_AI = artist .ArtistInspector (mlines .Line2D )
34
- _line_param_names = _line_AI .get_setters ()
35
- _line_param_aliases = [list (d .keys ())[0 ] for d in _line_AI .aliasd .values ()]
36
- _gridline_param_names = ['grid_' + name
37
- for name in _line_param_names + _line_param_aliases ]
38
-
39
31
40
32
class Tick (artist .Artist ):
41
33
"""
@@ -94,11 +86,6 @@ def __init__(self, axes, loc, label,
94
86
label2On = False ,
95
87
major = True ,
96
88
labelrotation = 0 ,
97
- grid_color = None ,
98
- grid_linestyle = None ,
99
- grid_linewidth = None ,
100
- grid_alpha = None ,
101
- ** kw # Other Line2D kwargs applied to gridlines.
102
89
):
103
90
"""
104
91
bbox is the Bound2D bounding box in display coords of the Axes
@@ -166,17 +153,6 @@ def __init__(self, axes, loc, label,
166
153
zorder = mlines .Line2D .zorder
167
154
self ._zorder = zorder
168
155
169
- self ._grid_color = (rcParams ['grid.color' ]
170
- if grid_color is None else grid_color )
171
- self ._grid_linestyle = (rcParams ['grid.linestyle' ]
172
- if grid_linestyle is None else grid_linestyle )
173
- self ._grid_linewidth = (rcParams ['grid.linewidth' ]
174
- if grid_linewidth is None else grid_linewidth )
175
- self ._grid_alpha = (rcParams ['grid.alpha' ]
176
- if grid_alpha is None else grid_alpha )
177
-
178
- self ._grid_kw = {k [5 :]: v for k , v in kw .items ()}
179
-
180
156
self .apply_tickdir (tickdir )
181
157
182
158
self .tick1line = self ._get_tick1line ()
@@ -392,14 +368,6 @@ def _apply_params(self, **kw):
392
368
v = getattr (self .label1 , 'get_' + k )()
393
369
setattr (self , '_label' + k , v )
394
370
395
- grid_list = [k for k in six .iteritems (kw )
396
- if k [0 ] in _gridline_param_names ]
397
- if grid_list :
398
- grid_kw = {k [5 :]: v for k , v in grid_list }
399
- self .gridline .set (** grid_kw )
400
- for k , v in six .iteritems (grid_kw ):
401
- setattr (self , '_grid_' + k , v )
402
-
403
371
def update_position (self , loc ):
404
372
'Set the location of tick in data coords with scalar *loc*'
405
373
raise NotImplementedError ('Derived must override' )
@@ -501,12 +469,11 @@ def _get_gridline(self):
501
469
'Get the default line2D instance'
502
470
# x in data coords, y in axes coords
503
471
l = mlines .Line2D (xdata = (0.0 , 0.0 ), ydata = (0 , 1.0 ),
504
- color = self ._grid_color ,
505
- linestyle = self ._grid_linestyle ,
506
- linewidth = self ._grid_linewidth ,
507
- alpha = self ._grid_alpha ,
508
- markersize = 0 ,
509
- ** self ._grid_kw )
472
+ color = rcParams ['grid.color' ],
473
+ linestyle = rcParams ['grid.linestyle' ],
474
+ linewidth = rcParams ['grid.linewidth' ],
475
+ alpha = rcParams ['grid.alpha' ],
476
+ markersize = 0 )
510
477
l .set_transform (self .axes .get_xaxis_transform (which = 'grid' ))
511
478
l .get_path ()._interpolation_steps = GRIDLINE_INTERPOLATION_STEPS
512
479
self ._set_artist_props (l )
@@ -625,12 +592,12 @@ def _get_gridline(self):
625
592
'Get the default line2D instance'
626
593
# x in axes coords, y in data coords
627
594
l = mlines .Line2D (xdata = (0 , 1 ), ydata = (0 , 0 ),
628
- color = self . _grid_color ,
629
- linestyle = self . _grid_linestyle ,
630
- linewidth = self . _grid_linewidth ,
631
- alpha = self . _grid_alpha ,
632
- markersize = 0 ,
633
- ** self . _grid_kw )
595
+ color = rcParams [ 'grid.color' ] ,
596
+ linestyle = rcParams [ 'grid.linestyle' ] ,
597
+ linewidth = rcParams [ 'grid.linewidth' ] ,
598
+ alpha = rcParams [ 'grid.alpha' ] ,
599
+ markersize = 0 )
600
+
634
601
l .set_transform (self .axes .get_yaxis_transform (which = 'grid' ))
635
602
l .get_path ()._interpolation_steps = GRIDLINE_INTERPOLATION_STEPS
636
603
self ._set_artist_props (l )
@@ -683,6 +650,13 @@ def __init__(self, axes, pickradius=15):
683
650
artist .Artist .__init__ (self )
684
651
self .set_figure (axes .figure )
685
652
653
+ # Keep track of setting to the default value, this allows use to know
654
+ # if any of the following values is explicitly set by the user, so as
655
+ # to not overwrite their settings with any of our 'auto' settings.
656
+ self .isDefault_majloc = True
657
+ self .isDefault_minloc = True
658
+ self .isDefault_majfmt = True
659
+ self .isDefault_minfmt = True
686
660
self .isDefault_label = True
687
661
688
662
self .axes = axes
@@ -771,10 +745,22 @@ def get_children(self):
771
745
772
746
def cla (self ):
773
747
'clear the current axis'
748
+ self .set_major_locator (mticker .AutoLocator ())
749
+ self .set_major_formatter (mticker .ScalarFormatter ())
750
+ self .set_minor_locator (mticker .NullLocator ())
751
+ self .set_minor_formatter (mticker .NullFormatter ())
774
752
775
- self .label .set_text ('' ) # self.set_label_text would change isDefault_
753
+ self .set_label_text ('' )
754
+ self ._set_artist_props (self .label )
776
755
777
- self ._set_scale ('linear' )
756
+ # Keep track of setting to the default value, this allows use to know
757
+ # if any of the following values is explicitly set by the user, so as
758
+ # to not overwrite their settings with any of our 'auto' settings.
759
+ self .isDefault_majloc = True
760
+ self .isDefault_minloc = True
761
+ self .isDefault_majfmt = True
762
+ self .isDefault_minfmt = True
763
+ self .isDefault_label = True
778
764
779
765
# Clear the callback registry for this axis, or it may "leak"
780
766
self .callbacks = cbook .CallbackRegistry ()
@@ -785,6 +771,9 @@ def cla(self):
785
771
self ._gridOnMinor = (rcParams ['axes.grid' ] and
786
772
rcParams ['axes.grid.which' ] in ('both' , 'minor' ))
787
773
774
+ self .label .set_text ('' )
775
+ self ._set_artist_props (self .label )
776
+
788
777
self .reset_ticks ()
789
778
790
779
self .converter = None
@@ -793,11 +782,9 @@ def cla(self):
793
782
self .stale = True
794
783
795
784
def reset_ticks (self ):
796
- """
797
- Re-initialize the major and minor Tick lists.
798
-
799
- Each list starts with a single fresh Tick.
800
- """
785
+ # build a few default ticks; grow as necessary later; only
786
+ # define 1 so properties set on ticks will be copied as they
787
+ # grow
801
788
del self .majorTicks [:]
802
789
del self .minorTicks [:]
803
790
@@ -806,11 +793,6 @@ def reset_ticks(self):
806
793
self ._lastNumMajorTicks = 1
807
794
self ._lastNumMinorTicks = 1
808
795
809
- try :
810
- self .set_clip_path (self .axes .patch )
811
- except AttributeError :
812
- pass
813
-
814
796
def set_tick_params (self , which = 'major' , reset = False , ** kw ):
815
797
"""
816
798
Set appearance parameters for ticks and ticklabels.
@@ -828,7 +810,6 @@ def set_tick_params(self, which='major', reset=False, **kw):
828
810
if reset :
829
811
d .clear ()
830
812
d .update (kwtrans )
831
-
832
813
if reset :
833
814
self .reset_ticks ()
834
815
else :
@@ -852,8 +833,7 @@ def _translate_tick_kw(kw, to_init_kw=True):
852
833
kwkeys1 = ['length' , 'direction' , 'left' , 'bottom' , 'right' , 'top' ,
853
834
'labelleft' , 'labelbottom' , 'labelright' , 'labeltop' ,
854
835
'labelrotation' ]
855
- kwkeys2 = _gridline_param_names
856
- kwkeys = kwkeys0 + kwkeys1 + kwkeys2
836
+ kwkeys = kwkeys0 + kwkeys1
857
837
kwtrans = dict ()
858
838
if to_init_kw :
859
839
if 'length' in kw :
@@ -995,7 +975,7 @@ def _update_ticks(self, renderer):
995
975
"""
996
976
997
977
interval = self .get_view_interval ()
998
- tick_tups = list (self .iter_ticks ()) # iter_ticks calls the locator
978
+ tick_tups = list (self .iter_ticks ())
999
979
if self ._smart_bounds and tick_tups :
1000
980
# handle inverted limits
1001
981
view_low , view_high = sorted (interval )
@@ -1421,21 +1401,30 @@ def grid(self, b=None, which='major', **kwargs):
1421
1401
if len (kwargs ):
1422
1402
b = True
1423
1403
which = which .lower ()
1424
- gridkw = {'grid_' + item [0 ]: item [1 ] for item in kwargs .items ()}
1425
1404
if which in ['minor' , 'both' ]:
1426
1405
if b is None :
1427
1406
self ._gridOnMinor = not self ._gridOnMinor
1428
1407
else :
1429
1408
self ._gridOnMinor = b
1430
- self .set_tick_params (which = 'minor' , gridOn = self ._gridOnMinor ,
1431
- ** gridkw )
1409
+ for tick in self .minorTicks : # don't use get_ticks here!
1410
+ if tick is None :
1411
+ continue
1412
+ tick .gridOn = self ._gridOnMinor
1413
+ if len (kwargs ):
1414
+ tick .gridline .update (kwargs )
1415
+ self ._minor_tick_kw ['gridOn' ] = self ._gridOnMinor
1432
1416
if which in ['major' , 'both' ]:
1433
1417
if b is None :
1434
1418
self ._gridOnMajor = not self ._gridOnMajor
1435
1419
else :
1436
1420
self ._gridOnMajor = b
1437
- self .set_tick_params (which = 'major' , gridOn = self ._gridOnMajor ,
1438
- ** gridkw )
1421
+ for tick in self .majorTicks : # don't use get_ticks here!
1422
+ if tick is None :
1423
+ continue
1424
+ tick .gridOn = self ._gridOnMajor
1425
+ if len (kwargs ):
1426
+ tick .gridline .update (kwargs )
1427
+ self ._major_tick_kw ['gridOn' ] = self ._gridOnMajor
1439
1428
self .stale = True
1440
1429
1441
1430
def update_units (self , data ):
@@ -1465,11 +1454,11 @@ def _update_axisinfo(self):
1465
1454
check the axis converter for the stored units to see if the
1466
1455
axis info needs to be updated
1467
1456
"""
1457
+
1468
1458
if self .converter is None :
1469
1459
return
1470
1460
1471
1461
info = self .converter .axisinfo (self .units , self )
1472
-
1473
1462
if info is None :
1474
1463
return
1475
1464
if info .majloc is not None and \
0 commit comments