Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib - How to set the distance (in mm/cm/points...) between the xticks

I've been looking on the internet for a long time but couldn't figure out how to make it. I need to draw several figures whose xticks are defined as numpy.arange(1,N), N being different for each figure. I want the spacing between the xticks to be identical on all figures (e.g. 1 cm), that is, the width of each figure must depend on the size of numpy.arange(1,N). Any idea of how to do that?

like image 819
ChristinaBB Avatar asked Aug 22 '12 17:08

ChristinaBB


1 Answers

I think you can do this with a combination of careful control of your axes size (as a fraction of the figure), ax.set_xlim and fig.set_size_inches (doc) to set the real size of the figure.

ex

 fig = plt.figure()
 ax = fig.add_axes([0,0,1,1])
 ax.set_xlim([0,N])
 fig.set_size_inches([N/2.54,h])
like image 89
tacaswell Avatar answered Oct 18 '22 19:10

tacaswell