From: Vineet J. <vi...@al...> - 2004-07-29 19:02:37
|
ok I think I've found the problem and a possible solution: left, width = 0.1, 0.8 x = range(100) closes1 = range(100, 200) closes2 = range(200, 300) closes3 = range(300, 400) f = figure(1, facecolor='w', figsize=(10, 7), dpi=96) rect2 = [left, 0.1, width, 0.8] axMiddle = axes(rect2, axisbg='#f6f6f6') axMiddle.yaxis.tick_left() plot_day_summary2(axMiddle, closes3, closes3, closes3, closes3) print axMiddle.get_ylim() axMiddle.plot(x, closes1, color='r', linewidth=1) print axMiddle.get_ylim() axMiddle.plot(x, closes2, color='r', linewidth=1) print axMiddle.get_ylim() This code prints which is wrong: (300.0, 400.0) (100.0, 200.0) (100.0, 300.0) However when I move the plot_day_summary2 to the end like: left, width = 0.1, 0.8 x = range(100) closes1 = range(100, 200) closes2 = range(200, 300) closes3 = range(300, 400) f = figure(1, facecolor='w', figsize=(10, 7), dpi=96) rect2 = [left, 0.1, width, 0.8] axMiddle = axes(rect2, axisbg='#f6f6f6') axMiddle.yaxis.tick_left() axMiddle.plot(x, closes1, color='r', linewidth=1) print axMiddle.get_ylim() axMiddle.plot(x, closes2, color='r', linewidth=1) print axMiddle.get_ylim() plot_day_summary2(axMiddle, closes3, closes3, closes3, closes3) print axMiddle.get_ylim() I get the correct value: (100.0, 200.0) (100.0, 300.0) (100.0, 400.0) -----Original Message----- From: John Hunter [mailto:jdh...@ac...] Sent: Thursday, July 29, 2004 11:17 AM To: Vineet Jain Subject: Re: [Matplotlib-users] Settling y-axis scaling >>>>> "Vineet" == Vineet Jain <vi...@al...> writes: Vineet> That does not seem to work (or I'm doing something Vineet> wrong). The last call to the function just returns the min Vineet> max from the last plot. Are you trying to get the min and max across several axes? ax.get_ylim should return the limits for a single axes which incorporates the data from several 'plot' commands on that axes. If you are trying to aggregate across axes, you'll need a different approach. If you could post some example code, it would probably help clarify. JDH |
From: John H. <jdh...@ac...> - 2004-07-29 19:59:12
|
>>>>> "Vineet" == Vineet Jain <vi...@al...> writes: Vineet> ok I think I've found the problem and a possible solution: The order of the plots should not make a difference. Clearly it does so this is a bug. Could you try editing matplotlib.axes.Axes.has_data (on or around line 323 of axes.py) and replace it with def has_data(self): return ( len(self._collections) + len(self._images) + len(self._lines) + len(self._patches))>0 and see if this fixes the problem. Ie, with this change, order of plot commands should not affect the final ylim. Thanks, JDH |
From: Vineet J. <vi...@al...> - 2004-07-29 21:43:20
|
After making changes to has_data I get the following: (0.0, 400.0) (0.0, 400.0) (0.0, 400.0) which is not correct it should be: (300.0, 400.0) (100.0, 400.0) (100.0, 400.0) -----Original Message----- From: mat...@li... [mailto:mat...@li...]On Behalf Of John Hunter Sent: Thursday, July 29, 2004 2:35 PM To: Vineet Jain Cc: matplotlib-users Subject: Re: [Matplotlib-users] Settling y-axis scaling >>>>> "Vineet" == Vineet Jain <vi...@al...> writes: Vineet> ok I think I've found the problem and a possible solution: The order of the plots should not make a difference. Clearly it does so this is a bug. Could you try editing matplotlib.axes.Axes.has_data (on or around line 323 of axes.py) and replace it with def has_data(self): return ( len(self._collections) + len(self._images) + len(self._lines) + len(self._patches))>0 and see if this fixes the problem. Ie, with this change, order of plot commands should not affect the final ylim. Thanks, JDH ------------------------------------------------------- This SF.Net email is sponsored by OSTG. Have you noticed the changes on Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now, one more big change to announce. We are now OSTG- Open Source Technology Group. Come see the changes on the new OSTG site. www.ostg.com _______________________________________________ Matplotlib-users mailing list Mat...@li... https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: John H. <jdh...@ac...> - 2004-08-02 16:20:07
|
>>>>> "Vineet" == Vineet Jain <vi...@al...> writes: Vineet> After making changes to has_data I get the following: Vineet> (0.0, 400.0) (0.0, 400.0) (0.0, 400.0) Vineet> which is not correct it should be: Vineet> (300.0, 400.0) (100.0, 400.0) (100.0, 400.0) I'm not sure this is incorrect. matplotlib distinguishes between the data limits and the view limits. The latter are automatically adjusted to include the data limits but may incorporate more. For example, the x data limits in [0.1, 10] may produce view limits [0,10]. If you need the view limits to always equal the data limits, you could provide a custom ticker, as described in http://matplotlib.sourceforge.net/matplotlib.ticker.html and illustrated in the example http://matplotlib.sourceforge.net/examples/custom_ticker1.py. You might want to verify that the data limits are correct by printing ax.dataLim.intervalx().get_bounds() # the x limits ax.dataLim.intervaly().get_bounds() # the y limits where ax is your Axes instance. You can compare these with ax.viewLim.intervalx().get_bounds() # the x limits ax.viewLim.intervaly().get_bounds() # the y limits JDH |
From: Vineet J. <vi...@al...> - 2004-08-03 12:42:37
|
That's fine. I'll start using ax.viewLim.intervaly().get_bounds() # the y limits to get the y limits. In any case though, the order in which the plot functions are called should not change the value returned by self.axMiddle.get_ylim. I think that is a bug. VJ -----Original Message----- From: mat...@li... [mailto:mat...@li...]On Behalf Of John Hunter Sent: Monday, August 02, 2004 10:56 AM To: Vineet Jain Cc: matplotlib-users Subject: Re: [Matplotlib-users] Settling y-axis scaling >>>>> "Vineet" == Vineet Jain <vi...@al...> writes: Vineet> After making changes to has_data I get the following: Vineet> (0.0, 400.0) (0.0, 400.0) (0.0, 400.0) Vineet> which is not correct it should be: Vineet> (300.0, 400.0) (100.0, 400.0) (100.0, 400.0) I'm not sure this is incorrect. matplotlib distinguishes between the data limits and the view limits. The latter are automatically adjusted to include the data limits but may incorporate more. For example, the x data limits in [0.1, 10] may produce view limits [0,10]. If you need the view limits to always equal the data limits, you could provide a custom ticker, as described in http://matplotlib.sourceforge.net/matplotlib.ticker.html and illustrated in the example http://matplotlib.sourceforge.net/examples/custom_ticker1.py. You might want to verify that the data limits are correct by printing ax.dataLim.intervalx().get_bounds() # the x limits ax.dataLim.intervaly().get_bounds() # the y limits where ax is your Axes instance. You can compare these with ax.viewLim.intervalx().get_bounds() # the x limits ax.viewLim.intervaly().get_bounds() # the y limits JDH ------------------------------------------------------- This SF.Net email is sponsored by OSTG. Have you noticed the changes on Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now, one more big change to announce. We are now OSTG- Open Source Technology Group. Come see the changes on the new OSTG site. www.ostg.com _______________________________________________ Matplotlib-users mailing list Mat...@li... https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: John H. <jdh...@ac...> - 2004-08-03 13:40:02
|
>>>>> "Vineet" == Vineet Jain <vi...@al...> writes: Vineet> That's fine. I'll start using Vineet> ax.viewLim.intervaly().get_bounds() # the y limits Vineet> to get the y limits. Hi Vineet, This is not recommended. I pointed you to limit attributes these so you can compare what is happening with the data and view limits separately, and to give you some insight into how to poke around if you need to. There is no reason for you to call ax.viewLim.intervaly().get_bounds() since this is what get_ylim calls anyway. The set_ylim and get_ylim functions are fixed as part of the matlab API; The viewLim and dataLim attributes are not. When possible, stick with the documented API, so your code will be compatible with future matplotlib releases. Vineet> In any case though, the order in which the plot functions Vineet> are called should not change the value returned by Vineet> self.axMiddle.get_ylim. I think that is a bug. There may be a bug, but let's be clear to find out. Here is what is happening. Every time you issue a plot command, the ax.dataLim are updated. These should exactly bound the min and max of the x and y range of your data. After that, ax.autoscale_view is called. This updates the min and max of the x and y *view* limits, which should include, but may exceed, the datalim. Exactly how this view limit update is done depends on the tick locator you have chosen. The default locator is matplotlib.ticker.AutoLocator, but you can customize this. if you issue repeated plot commands ax.plot(something) ax.plot(something_else) ax.plot(still_mode) print 'datalim', ax.dataLim.intervaly().get_bounds() print 'viewlim', ax.get_ylim() neither the viewlim nor the datalim after all plot commands have been issued should not be affected by the order of the plot commands. Of course, you need to apply the patch I posted in my previous email (to the has_data function) because there was a bug. The viewlim *will* be changed after each plot command, and will depend on the order, as in ax.plot(something) print 'viewlim', ax.get_ylim() ax.plot(something_else) print 'viewlim', ax.get_ylim() ax.plot(still_mode) print 'viewlim', ax.get_ylim() but again, the final viewlim should be order independent. Is this what you observe? If the plot order does affect the final limits, let me know. If the viewlim differs from the data lim, that is unsurprising, as that is by design. If you are unhappy with the way to the autolocator is choosing the view limits, you have a couple of choices: 1) let me know by giving me the requisite datalim and viewlim boundaries, what is happening, and what you think should be happening and I'll look in to fixing it or 2) use a custom locator that autoscales the view limits in the way you want. JDH |