2009-11-13 92 views
17

我正在Python和matplotlib中繪製圖表,我發現這個圖表非常靈活,直到現在。matplotlib上的多個網格

我無法找到如何做的唯一的事情就是讓我的情節有多個網格。 我已經調查了documentation,但這只是爲線條樣式...

我在想像兩個情節每個與不同的網格,這將重疊他們。

因此,例如我想使這個圖:

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

有類似的格子標誌,因爲這一個:

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

而到的是,我的意思是,更多的頻繁的網格重點之間顏色較淺。

+0

好像你正在尋找輕微滴答聲 – SilentGhost 2009-11-13 15:47:29

回答

32

如何像這樣(改編自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() 

enter image description here

+0

這似乎正是我要找的!我會今天嘗試,並在其工作後立即給出答案。謝謝 – Santi 2009-11-14 13:52:23