python matplotlib 上的多个网格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1729995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple grids on matplotlib
提问by Santi
I'm making plots in Python and matplotlib, which I found huge and flexible, till now.
到目前为止,我正在用 Python 和 matplotlib 绘制绘图,我发现它们庞大而灵活。
The only thing I couldn't find how to do, is to make my plot have multiple grids. I've looked into the documentation, but that's just for line style...
我唯一找不到怎么做的就是让我的情节有多个网格。我已经查看了文档,但这只是针对线条样式...
I'm thinking on something like two plots each one with a different grid, which will overlap them.
我正在考虑类似两个图,每个图都有不同的网格,它们会重叠。
So, for example I want to make this graph:
所以,例如我想制作这个图:
Alt text http://img137.imageshack.us/img137/2017/waittimeprobability.png
替代文字 http://img137.imageshack.us/img137/2017/waittimeprobability.png
Have a similar grid marks as this one:
有一个与此类似的网格标记:
Alt text http://img137.imageshack.us/img137/6122/saucelabssauceloadday.png
替代文字 http://img137.imageshack.us/img137/6122/saucelabssauceloadday.png
And by that, I mean, more frequent grids with lighter color between important points.
我的意思是,重要点之间颜色较浅的更频繁的网格。
回答by Mark
How about something like this (adapted from here):
这样的事情怎么样(改编自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()