matplotlib-users

 [Matplotlib-users] ymax From: kamel maths - 2012-06-06 19:32:22 Attachments: Message as HTML ```Hi, for this script: ------------------------------------ from pylab import * fig = figure() ax = fig.add_subplot(111) ax.axis('equal') x = linspace(-2, 3, 50) ax.plot(x, sin(x)) show() --------------------------------- If I try to get ymax with ax.get_ylim(), i obtain 1.0 whereas I observe it is 2.0. How can I obtain 2.0 for ymax ? Thanks. Kamel ```
 Re: [Matplotlib-users] ymax From: Tony Yu - 2012-06-06 22:13:41 Attachments: Message as HTML ```On Wed, Jun 6, 2012 at 3:32 PM, kamel maths wrote: > Hi, > > for this script: > ------------------------------------ > from pylab import * > > fig = figure() > ax = fig.add_subplot(111) > ax.axis('equal') > > x = linspace(-2, 3, 50) > ax.plot(x, sin(x)) > > show() > --------------------------------- > If I try to get ymax with ax.get_ylim(), i obtain 1.0 whereas I observe it > is 2.0. > How can I obtain 2.0 for ymax ? > > Thanks. > > Kamel > Hi Kamel, I'm not seeing the same result: I actually get back (-1.94, 1.94) from `get_ylim`. When do you call `get_ylim`? Do you call it *after* calling `plot`? -Tony ```
 Re: [Matplotlib-users] ymax From: Benjamin Root - 2012-06-07 02:00:33 Attachments: Message as HTML ```On Wed, Jun 6, 2012 at 6:12 PM, Tony Yu wrote: > > > On Wed, Jun 6, 2012 at 3:32 PM, kamel maths wrote: > >> Hi, >> >> for this script: >> ------------------------------------ >> from pylab import * >> >> fig = figure() >> ax = fig.add_subplot(111) >> ax.axis('equal') >> >> x = linspace(-2, 3, 50) >> ax.plot(x, sin(x)) >> >> show() >> --------------------------------- >> If I try to get ymax with ax.get_ylim(), i obtain 1.0 whereas I observe >> it is 2.0. >> How can I obtain 2.0 for ymax ? >> >> Thanks. >> >> Kamel >> > > Hi Kamel, > > I'm not seeing the same result: I actually get back (-1.94, 1.94) from > `get_ylim`. When do you call `get_ylim`? Do you call it *after* calling > `plot`? > > -Tony > > Or, more likely, are you calling it *after* you close the figure? If so, then the axes has already been cleared and you are merely finding the limits for a newly created (but unshown) figure. Make sure you get the limits after the plotting, but before the show(). Ben Root ```
 Re: [Matplotlib-users] ymax From: Tony Yu - 2012-06-07 16:37:33 Attachments: Message as HTML ```On Thu, Jun 7, 2012 at 12:14 PM, kamel maths wrote: > Thanks for your answers. > > It is not very clear for me yet. This a script I tested. > ---------------------------------------------- > from pylab import * > > fig = figure() > ax = fig.add_subplot(111) > ax.axis('equal') > > x = linspace(-2, 3, 50) > ax.plot(x, sin(x)) > > ylim = ax.get_ylim() > print(ylim) > > show() > > ylim = ax.get_ylim() > print(ylim) > ------------------------------------ > With the first print, I obtain (-1,1) and with the second one, after > having closed the figure showed, I obtain (-1.94,1.94). But I would like to > obtain (-1.94,1.94) with the first one in order to use this data in the > figure. > Is it possible ? > > Hi Kamel, (I'm recopying to the list; unfortunately, the mailing list doesn't do this automatically) Well, this is strange: I swear I tested this yesterday, and I got (-1.94, 1.94) when calling `get_ylim` before `show`. But when I test this today, I get (-1, 1) with the call before `show`. I guess the initial call to `get_ylim` returns that data limits (which are (-1, 1) in this case), but the call to `axis('equal')` results in a rescaling at draw time. If you're just trying to readjust the plot before the plot blocks execution, you can run `draw()` right before calling `get_ylim`. There may be a better approach, though. -Tony ```
 Re: [Matplotlib-users] ymax From: kamel maths - 2012-06-07 16:47:16 Attachments: Message as HTML ```Thank you very much. It works at last. Kamel 2012/6/7 Tony Yu > > On Thu, Jun 7, 2012 at 12:14 PM, kamel maths wrote: > >> Thanks for your answers. >> >> It is not very clear for me yet. This a script I tested. >> ---------------------------------------------- >> from pylab import * >> >> fig = figure() >> ax = fig.add_subplot(111) >> ax.axis('equal') >> >> x = linspace(-2, 3, 50) >> ax.plot(x, sin(x)) >> >> ylim = ax.get_ylim() >> print(ylim) >> >> show() >> >> ylim = ax.get_ylim() >> print(ylim) >> ------------------------------------ >> With the first print, I obtain (-1,1) and with the second one, after >> having closed the figure showed, I obtain (-1.94,1.94). But I would like to >> obtain (-1.94,1.94) with the first one in order to use this data in the >> figure. >> Is it possible ? >> >> > Hi Kamel, > > (I'm recopying to the list; unfortunately, the mailing list doesn't do > this automatically) > > Well, this is strange: I swear I tested this yesterday, and I got (-1.94, > 1.94) when calling `get_ylim` before `show`. But when I test this today, I > get (-1, 1) with the call before `show`. > > I guess the initial call to `get_ylim` returns that data limits (which are > (-1, 1) in this case), but the call to `axis('equal')` results in a > rescaling at draw time. > > If you're just trying to readjust the plot before the plot blocks > execution, you can run `draw()` right before calling `get_ylim`. There may > be a better approach, though. > > -Tony > > > ```