【问题标题】:Multiple grids on matplotlibmatplotlib 上的多个网格
【发布时间】:2010-12-16 08:16:22
【问题描述】:

我正在使用 Python 和 matplotlib 绘制绘图,我发现它们非常庞大且灵活,直到现在。

我唯一找不到的方法是让我的情节有多个网格。 我查看了documentation,但这只是线条样式...

我正在考虑类似两个地块,每个地块都有不同的网格,它们会重叠。

所以,例如我想制作这个图表:

Alt text http://img137.imageshack.us/img137/2017/waittimeprobability.png

有一个和这个类似的网格标记:

Alt text http://img137.imageshack.us/img137/6122/saucelabssauceloadday.png

我的意思是,更频繁的网格在重要点之间具有较浅的颜色。

【问题讨论】:

  • 您似乎在寻找小蜱

标签: python matplotlib


【解决方案1】:

这样的事情怎么样(改编自here):

from pylab import *
from matplotlib.ticker import MultipleLocator, FormatStrFormatter

t = arange(0.0, 100.0, 0.1)
s = sin(0.1*pi*t)*exp(-t*0.01)

ax = subplot(111)
plot(t,s)

ax.xaxis.set_major_locator(MultipleLocator(20))
ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
ax.xaxis.set_minor_locator(MultipleLocator(5))

ax.yaxis.set_major_locator(MultipleLocator(0.5))
ax.yaxis.set_minor_locator(MultipleLocator(0.1))

ax.xaxis.grid(True,'minor')
ax.yaxis.grid(True,'minor')
ax.xaxis.grid(True,'major',linewidth=2)
ax.yaxis.grid(True,'major',linewidth=2)

show()

【讨论】:

  • 这似乎正是我要找的!我今天会尝试一下,并在它起作用后立即标记您的答案。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-13
  • 2018-08-28
  • 1970-01-01
  • 2015-07-04
  • 1970-01-01
  • 2011-12-02
相关资源
最近更新 更多