@@ -782,10 +782,10 @@ def clear(self):
782782 self .callbacks = cbook .CallbackRegistry ()
783783
784784 # whether the grids are on
785- self ._gridOnMajor = (
785+ self ._major_tick_kw [ 'gridOn' ] = (
786786 mpl .rcParams ['axes.grid' ] and
787787 mpl .rcParams ['axes.grid.which' ] in ('both' , 'major' ))
788- self ._gridOnMinor = (
788+ self ._minor_tick_kw [ 'gridOn' ] = (
789789 mpl .rcParams ['axes.grid' ] and
790790 mpl .rcParams ['axes.grid.which' ] in ('both' , 'minor' ))
791791
@@ -1390,7 +1390,6 @@ def get_major_ticks(self, numticks=None):
13901390 # Update the new tick label properties from the old.
13911391 tick = self ._get_tick (major = True )
13921392 self .majorTicks .append (tick )
1393- tick .gridline .set_visible (self ._gridOnMajor )
13941393 self ._copy_tick_props (self .majorTicks [0 ], tick )
13951394
13961395 return self .majorTicks [:numticks ]
@@ -1404,7 +1403,6 @@ def get_minor_ticks(self, numticks=None):
14041403 # Update the new tick label properties from the old.
14051404 tick = self ._get_tick (major = False )
14061405 self .minorTicks .append (tick )
1407- tick .gridline .set_visible (self ._gridOnMinor )
14081406 self ._copy_tick_props (self .minorTicks [0 ], tick )
14091407
14101408 return self .minorTicks [:numticks ]
@@ -1429,32 +1427,37 @@ def grid(self, b=None, which='major', **kwargs):
14291427 Define the line properties of the grid, e.g.::
14301428
14311429 grid(color='r', linestyle='-', linewidth=2)
1432-
14331430 """
1434- if len (kwargs ):
1435- if not b and b is not None : # something false-like but not None
1431+ if b is not None :
1432+ if 'visible' in kwargs and bool (b ) != bool (kwargs ['visible' ]):
1433+ raise ValueError (
1434+ "'b' and 'visible' specify inconsistent grid visibilities" )
1435+ if kwargs and not b : # something false-like but not None
14361436 cbook ._warn_external ('First parameter to grid() is false, '
14371437 'but line properties are supplied. The '
14381438 'grid will be enabled.' )
1439- b = True
1439+ b = True
14401440 which = which .lower ()
14411441 _api .check_in_list (['major' , 'minor' , 'both' ], which = which )
14421442 gridkw = {'grid_' + item [0 ]: item [1 ] for item in kwargs .items ()}
1443+ if 'grid_visible' in gridkw :
1444+ forced_visibility = True
1445+ gridkw ['gridOn' ] = gridkw .pop ('grid_visible' )
1446+ else :
1447+ forced_visibility = False
14431448
14441449 if which in ['minor' , 'both' ]:
1445- if b is None :
1446- self ._gridOnMinor = not self ._gridOnMinor
1447- else :
1448- self ._gridOnMinor = b
1449- self .set_tick_params (which = 'minor' , gridOn = self ._gridOnMinor ,
1450- ** gridkw )
1450+ if b is None and not forced_visibility :
1451+ gridkw ['gridOn' ] = not self ._minor_tick_kw ['gridOn' ]
1452+ elif b is not None :
1453+ gridkw ['gridOn' ] = b
1454+ self .set_tick_params (which = 'minor' , ** gridkw )
14511455 if which in ['major' , 'both' ]:
1452- if b is None :
1453- self ._gridOnMajor = not self ._gridOnMajor
1454- else :
1455- self ._gridOnMajor = b
1456- self .set_tick_params (which = 'major' , gridOn = self ._gridOnMajor ,
1457- ** gridkw )
1456+ if b is None and not forced_visibility :
1457+ gridkw ['gridOn' ] = not self ._major_tick_kw ['gridOn' ]
1458+ elif b is not None :
1459+ gridkw ['gridOn' ] = b
1460+ self .set_tick_params (which = 'major' , ** gridkw )
14581461 self .stale = True
14591462
14601463 def update_units (self , data ):
0 commit comments