@@ -430,12 +430,12 @@ def trigger(self, sender, event, data=None):
430430 if ax is None :
431431 return
432432 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 )
434434 except ValueError :
435435 pass
436436 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" )
439439 ax .figure .canvas .draw_idle ()
440440
441441 @staticmethod
@@ -461,13 +461,18 @@ class ToolGrid(_ToolGridBase):
461461 default_keymap = rcParams ['keymap.grid' ]
462462
463463 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
464468 x_state , y_state = map (self ._get_uniform_grid_state ,
465469 [ax .xaxis .majorTicks , ax .yaxis .majorTicks ])
466470 cycle = self ._cycle
467471 # Bail out (via ValueError) if major grids are not in a uniform state.
468472 x_state , y_state = (
469473 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" )
471476
472477
473478class ToolMinorGrid (_ToolGridBase ):
@@ -487,7 +492,7 @@ def _get_next_grid_states(self, ax):
487492 # Bail out (via ValueError) if minor grids are not in a uniform state.
488493 x_state , y_state = (
489494 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"
491496
492497
493498class ToolFullScreen (ToolToggleBase ):
0 commit comments