Matplotlib:检查网格是否打开? [英] Matplotlib: check if grid is on?
问题描述
from matplotlib.figure import图
fig = figure()
ax = fig.add_subplot(111)
ax.grid(True)
但是,它似乎没有任何方法来确定网格的状态(on / True或off / False)?
源代码揭示了隐藏在 Axis
类中的私有变量: self._gridOnMinor
和 self._gridOnMajor
访问这些可以通过以下方式完成:
ax.xaxis._gridOnMinor
ax.yaxis._gridOnMinor
等等......
但是因为这些被指定为私有,所以我有点担心这样做。
这是否是唯一的检查网格是打开还是关闭的方法?
我有同样的问题,必须在我的实现一个特殊的变量CLAS要注意电网状态。所以我想你要么保持你的危险的私人方法或我的丑陋的方法:($ / b>
Matplotlib has a very easy method for toggling gridlines on a figure:
from matplotlib.figure import Figure
fig = Figure()
ax = fig.add_subplot(111)
ax.grid(True)
But it does not seem to have any method to determine the state of the grid (on/True or off/False)?
A look at the source code reveals that buried in the Axis
class, there are the private variables: self._gridOnMinor
and self._gridOnMajor
Accessing these could be done by:
ax.xaxis._gridOnMinor
ax.yaxis._gridOnMinor
and so on... but as these are designated as private, I'm a bit wary about doing so.
Is this really the only way to check whether the grid is on or off?
I had the same problems and had to implement a special variable in my class to be aware of grid state. So I guess you either stay with your "dangerous private method" or with my "ugly method" :(
这篇关于Matplotlib:检查网格是否打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!