@@ -778,10 +778,10 @@ def cla(self):
778778 self .callbacks = cbook .CallbackRegistry ()
779779
780780 # whether the grids are on
781- self ._gridOnMajor = (
781+ self ._major_tick_kw [ 'gridOn' ] = (
782782 mpl .rcParams ['axes.grid' ] and
783783 mpl .rcParams ['axes.grid.which' ] in ('both' , 'major' ))
784- self ._gridOnMinor = (
784+ self ._minor_tick_kw [ 'gridOn' ] = (
785785 mpl .rcParams ['axes.grid' ] and
786786 mpl .rcParams ['axes.grid.which' ] in ('both' , 'minor' ))
787787
@@ -1381,7 +1381,6 @@ def get_major_ticks(self, numticks=None):
13811381 # Update the new tick label properties from the old.
13821382 tick = self ._get_tick (major = True )
13831383 self .majorTicks .append (tick )
1384- tick .gridline .set_visible (self ._gridOnMajor )
13851384 self ._copy_tick_props (self .majorTicks [0 ], tick )
13861385
13871386 return self .majorTicks [:numticks ]
@@ -1395,7 +1394,6 @@ def get_minor_ticks(self, numticks=None):
13951394 # Update the new tick label properties from the old.
13961395 tick = self ._get_tick (major = False )
13971396 self .minorTicks .append (tick )
1398- tick .gridline .set_visible (self ._gridOnMinor )
13991397 self ._copy_tick_props (self .minorTicks [0 ], tick )
14001398
14011399 return self .minorTicks [:numticks ]
@@ -1420,32 +1418,37 @@ def grid(self, b=None, which='major', **kwargs):
14201418 Define the line properties of the grid, e.g.::
14211419
14221420 grid(color='r', linestyle='-', linewidth=2)
1423-
14241421 """
1425- if len (kwargs ):
1426- if not b and b is not None : # something false-like but not None
1422+ if b is not None :
1423+ if 'visible' in kwargs and bool (b ) != bool (kwargs ['visible' ]):
1424+ raise ValueError (
1425+ "'b' and 'visible' specify inconsistent grid visibilities" )
1426+ if kwargs and not b : # something false-like but not None
14271427 cbook ._warn_external ('First parameter to grid() is false, '
14281428 'but line properties are supplied. The '
14291429 'grid will be enabled.' )
1430- b = True
1430+ b = True
14311431 which = which .lower ()
14321432 cbook ._check_in_list (['major' , 'minor' , 'both' ], which = which )
14331433 gridkw = {'grid_' + item [0 ]: item [1 ] for item in kwargs .items ()}
1434+ if 'grid_visible' in gridkw :
1435+ forced_visibility = True
1436+ gridkw ['gridOn' ] = gridkw .pop ('grid_visible' )
1437+ else :
1438+ forced_visibility = False
14341439
14351440 if which in ['minor' , 'both' ]:
1436- if b is None :
1437- self ._gridOnMinor = not self ._gridOnMinor
1438- else :
1439- self ._gridOnMinor = b
1440- self .set_tick_params (which = 'minor' , gridOn = self ._gridOnMinor ,
1441- ** gridkw )
1441+ if b is None and not forced_visibility :
1442+ gridkw ['gridOn' ] = not self ._minor_tick_kw ['gridOn' ]
1443+ elif b is not None :
1444+ gridkw ['gridOn' ] = b
1445+ self .set_tick_params (which = 'minor' , ** gridkw )
14421446 if which in ['major' , 'both' ]:
1443- if b is None :
1444- self ._gridOnMajor = not self ._gridOnMajor
1445- else :
1446- self ._gridOnMajor = b
1447- self .set_tick_params (which = 'major' , gridOn = self ._gridOnMajor ,
1448- ** gridkw )
1447+ if b is None and not forced_visibility :
1448+ gridkw ['gridOn' ] = not self ._major_tick_kw ['gridOn' ]
1449+ elif b is not None :
1450+ gridkw ['gridOn' ] = b
1451+ self .set_tick_params (which = 'major' , ** gridkw )
14491452 self .stale = True
14501453
14511454 def update_units (self , data ):
0 commit comments