@@ -790,10 +790,10 @@ def clear(self):
790
790
self .callbacks = cbook .CallbackRegistry ()
791
791
792
792
# whether the grids are on
793
- self ._gridOnMajor = (
793
+ self ._major_tick_kw [ 'gridOn' ] = (
794
794
mpl .rcParams ['axes.grid' ] and
795
795
mpl .rcParams ['axes.grid.which' ] in ('both' , 'major' ))
796
- self ._gridOnMinor = (
796
+ self ._minor_tick_kw [ 'gridOn' ] = (
797
797
mpl .rcParams ['axes.grid' ] and
798
798
mpl .rcParams ['axes.grid.which' ] in ('both' , 'minor' ))
799
799
@@ -1398,7 +1398,6 @@ def get_major_ticks(self, numticks=None):
1398
1398
# Update the new tick label properties from the old.
1399
1399
tick = self ._get_tick (major = True )
1400
1400
self .majorTicks .append (tick )
1401
- tick .gridline .set_visible (self ._gridOnMajor )
1402
1401
self ._copy_tick_props (self .majorTicks [0 ], tick )
1403
1402
1404
1403
return self .majorTicks [:numticks ]
@@ -1412,7 +1411,6 @@ def get_minor_ticks(self, numticks=None):
1412
1411
# Update the new tick label properties from the old.
1413
1412
tick = self ._get_tick (major = False )
1414
1413
self .minorTicks .append (tick )
1415
- tick .gridline .set_visible (self ._gridOnMinor )
1416
1414
self ._copy_tick_props (self .minorTicks [0 ], tick )
1417
1415
1418
1416
return self .minorTicks [:numticks ]
@@ -1437,32 +1435,37 @@ def grid(self, b=None, which='major', **kwargs):
1437
1435
Define the line properties of the grid, e.g.::
1438
1436
1439
1437
grid(color='r', linestyle='-', linewidth=2)
1440
-
1441
1438
"""
1442
- if len (kwargs ):
1443
- if not b and b is not None : # something false-like but not None
1439
+ if b is not None :
1440
+ if 'visible' in kwargs and bool (b ) != bool (kwargs ['visible' ]):
1441
+ raise ValueError (
1442
+ "'b' and 'visible' specify inconsistent grid visibilities" )
1443
+ if kwargs and not b : # something false-like but not None
1444
1444
cbook ._warn_external ('First parameter to grid() is false, '
1445
1445
'but line properties are supplied. The '
1446
1446
'grid will be enabled.' )
1447
- b = True
1447
+ b = True
1448
1448
which = which .lower ()
1449
1449
_api .check_in_list (['major' , 'minor' , 'both' ], which = which )
1450
1450
gridkw = {'grid_' + item [0 ]: item [1 ] for item in kwargs .items ()}
1451
+ if 'grid_visible' in gridkw :
1452
+ forced_visibility = True
1453
+ gridkw ['gridOn' ] = gridkw .pop ('grid_visible' )
1454
+ else :
1455
+ forced_visibility = False
1451
1456
1452
1457
if which in ['minor' , 'both' ]:
1453
- if b is None :
1454
- self ._gridOnMinor = not self ._gridOnMinor
1455
- else :
1456
- self ._gridOnMinor = b
1457
- self .set_tick_params (which = 'minor' , gridOn = self ._gridOnMinor ,
1458
- ** gridkw )
1458
+ if b is None and not forced_visibility :
1459
+ gridkw ['gridOn' ] = not self ._minor_tick_kw ['gridOn' ]
1460
+ elif b is not None :
1461
+ gridkw ['gridOn' ] = b
1462
+ self .set_tick_params (which = 'minor' , ** gridkw )
1459
1463
if which in ['major' , 'both' ]:
1460
- if b is None :
1461
- self ._gridOnMajor = not self ._gridOnMajor
1462
- else :
1463
- self ._gridOnMajor = b
1464
- self .set_tick_params (which = 'major' , gridOn = self ._gridOnMajor ,
1465
- ** gridkw )
1464
+ if b is None and not forced_visibility :
1465
+ gridkw ['gridOn' ] = not self ._major_tick_kw ['gridOn' ]
1466
+ elif b is not None :
1467
+ gridkw ['gridOn' ] = b
1468
+ self .set_tick_params (which = 'major' , ** gridkw )
1466
1469
self .stale = True
1467
1470
1468
1471
def update_units (self , data ):
0 commit comments