17

I'm making plots in Python and matplotlib, which I found huge and flexible, till now.

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

Have a similar grid marks as this one:

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

And by that, I mean, more frequent grids with lighter color between important points.

1
  • it seems you're looking for minor ticks Commented Nov 13, 2009 at 15:47

1 Answer 1

34

How about something like this (adapted from 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

Sign up to request clarification or add additional context in comments.

1 Comment

That seems to be exactly what I'm looking for! I'll try it today and mark your answer as soon as it works. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.