Matplotlib: check if grid is on?

Matplotlib has a very easy way to switch grid lines to a shape:

from matplotlib.figure import Figure fig = Figure() ax = fig.add_subplot(111) ax.grid(True) 

But he has no way to determine the state of the grid (on / True or off / False)?

A look at the source code shows that it is similar to the Axis class, there are private variables: self._gridOnMinor and self._gridOnMajor

You can access them using:

 ax.xaxis._gridOnMinor ax.yaxis._gridOnMinor 

and so on ... but since they are assigned as private, I am a little wary of this.

Is this really the only way to check if the grid is turned on?

+3
source share
1 answer

I had the same problems and I had to implement a special variable in my class to know the state of the grid. Therefore, I think you are either left with your "dangerous personal method" or with my "ugly method" :(

+1
source

All Articles