code: def restore_grid(func):
      
      @wraps(func)
      def wrapped_func(self, *args, **kwargs):
          grid = (self.xaxis._gridOnMinor, self.xaxis._gridOnMajor,
                  self.yaxis._gridOnMinor, self.yaxis._gridOnMajor)
          try:
              return func(self, *args, **kwargs)
          finally:
              # reset grid
              self.xaxis.grid(grid[0], which="minor")
              self.xaxis.grid(grid[1], which="major")
              self.yaxis.grid(grid[2], which="minor")
              self.yaxis.grid(grid[3], which="major")
      return wrapped_func
docs: Wrap ``func`` to preserve the Axes current grid settings.