@@ -430,12 +430,12 @@ def trigger(self, sender, event, data=None):
430
430
if ax is None :
431
431
return
432
432
try :
433
- x_state , y_state , which = self ._get_next_grid_states (ax )
433
+ x_state , x_which , y_state , y_which = self ._get_next_grid_states (ax )
434
434
except ValueError :
435
435
pass
436
436
else :
437
- ax .grid (x_state , which = which , axis = "x" )
438
- ax .grid (y_state , which = which , axis = "y" )
437
+ ax .grid (x_state , which = x_which , axis = "x" )
438
+ ax .grid (y_state , which = y_which , axis = "y" )
439
439
ax .figure .canvas .draw_idle ()
440
440
441
441
@staticmethod
@@ -461,13 +461,18 @@ class ToolGrid(_ToolGridBase):
461
461
default_keymap = rcParams ['keymap.grid' ]
462
462
463
463
def _get_next_grid_states (self , ax ):
464
+ if None in map (self ._get_uniform_grid_state ,
465
+ [ax .xaxis .minorTicks , ax .yaxis .minorTicks ]):
466
+ # Bail out if minor grids are not in a uniform state.
467
+ raise ValueError
464
468
x_state , y_state = map (self ._get_uniform_grid_state ,
465
469
[ax .xaxis .majorTicks , ax .yaxis .majorTicks ])
466
470
cycle = self ._cycle
467
471
# Bail out (via ValueError) if major grids are not in a uniform state.
468
472
x_state , y_state = (
469
473
cycle [(cycle .index ((x_state , y_state )) + 1 ) % len (cycle )])
470
- return x_state , y_state , "major"
474
+ return (x_state , "major" if x_state else "both" ,
475
+ y_state , "major" if y_state else "both" )
471
476
472
477
473
478
class ToolMinorGrid (_ToolGridBase ):
@@ -487,7 +492,7 @@ def _get_next_grid_states(self, ax):
487
492
# Bail out (via ValueError) if minor grids are not in a uniform state.
488
493
x_state , y_state = (
489
494
cycle [(cycle .index ((x_state , y_state )) + 1 ) % len (cycle )])
490
- return x_state , y_state , "both"
495
+ return x_state , "both" , y_state , "both"
491
496
492
497
493
498
class ToolFullScreen (ToolToggleBase ):
0 commit comments