1

I have a plot in matplotlib and I would like to resize automatically the xlim based on the view fixed by ylim. How to do that ?

Currently I write :

plt.ylim(0, 10)

And the problem occurs when I have a set of data that goes from y=0 to y=20, then the xlim remain unchanged : I would like to have it automatically rescaled for the view corresponding to plt.ylim(0, 10).

Vincent
  • 57,703
  • 61
  • 205
  • 388
  • 3
    Can you write a wrapper function that modifies both xlim and ylim at the same time? Even more radically you could try to patch in a version of ylim that did this. – Adrian Ratnapala May 07 '13 at 15:38
  • I don't quite understand your question. Can you clarify it a bit more, maybe with an example? You may find the get_ylim() method of the axes instance useful. – Thom Chubb May 07 '13 at 23:31
  • Exactly Thom, `ax.set_xlim(ax.get_ylim())` would do the trick. – Rutger Kassies May 08 '13 at 06:51
  • @RutgerKassies: that does the trick only if you plot `y=x`. The question is about an automatic way to get `xlim` adjusted according to what is shown in the figure – Francesco Montesano May 08 '13 at 08:35

0 Answers0