Determine the size of the mesh in the plot using Matplotlib

I plan to use Matplotlib in Python. I want to create a plot with a grid, and here is an example from a graphic tutorial. In my plot range, if the y axis is from 0 to 14, and if I use pylab.grid(True) , then it creates a grid with a square of two, but I want the size to be 1. How can I force it?

+19
python matplotlib
May 04 '12 at 17:53
source share
2 answers

Try using ax.grid(True, which='both') to place grid lines on primary and secondary ticks, as suggested here .

EDIT: or just set your checkboxes manually, for example:

 import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) ax.plot([1,2,3,14],'ro-') # set your ticks manually ax.xaxis.set_ticks([1.,2.,3.,10.]) ax.grid(True) plt.show() 
+22
May 04 '12 at 18:00
source share
— -

If you want to follow along with the example you provided:

 >>> import numpy >>> import pylab >>> t = numpy.arange(0.0, 1.0+0.1, 0.01) >>> s = numpy.cos(2*2*numpy.pi*t) >>> pylab.plot(t,s) >>> pylab.grid(True) >>> pylab.xticks([i/10.0 for i in range(0,12)]) >>> pylab.show() 
+6
May 4 '12 at 18:28
source share



All Articles