|
From: Thomas R. <tho...@gm...> - 2009-02-21 14:00:47
|
Hello, I am using matplotlib to show an image using: fig = figure() ax = fig.add_subplot(111) ax.imshow(image) After doing this, I want to find the contours for a different image (with different dimensions), but I do not want to interact with the current figure or axes, I just want to retrieve the set of LineCollection objects for the contours. The issue is that if I do c = contour(image2) the contours are stored inside c, but at the same time they are plotted in the current figure. If I use ax.contour(image2) then the contours are not plotted immediately, but the view interval has already been changed inside ax. So essentially, I am wondering if it is possible to retrieve a set of LineCollection objects without acting in any way on the current figure/axes. Thanks for any help, Thomas |
|
From: Eric F. <ef...@ha...> - 2009-02-21 19:34:22
|
Thomas Robitaille wrote: > Hello, > > I am using matplotlib to show an image using: > > fig = figure() > ax = fig.add_subplot(111) > ax.imshow(image) > > After doing this, I want to find the contours for a different image > (with different dimensions), but I do not want to interact with the > current figure or axes, I just want to retrieve the set of > LineCollection objects for the contours. The issue is that if I do > > c = contour(image2) > > the contours are stored inside c, but at the same time they are plotted > in the current figure. If I use > > ax.contour(image2) > > then the contours are not plotted immediately, but the view interval has > already been changed inside ax. The workaround for now may be to call ax.set_autoscale_on(False) before your call to ax.contour. You could also save the datalim before and restore them afterwards. This sort of request has come up before, though, and the longer-term solution might be some refactoring in contour.py. As it is, everything is done when the ContourSet is instantiated; one does not have the option of simply calculating the contours, for example. Eric > > So essentially, I am wondering if it is possible to retrieve a set of > LineCollection objects without acting in any way on the current figure/axes. > > Thanks for any help, > > Thomas > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
|
From: Thomas R. <tho...@gm...> - 2009-02-22 22:32:55
|
Hi Eric, Thanks for your help! Unfortunately, ax.set_autoscale_on(False) does not work - I had already tried this before unsuccessfully. Consider the following: from pylab import * import numpy as np def test(): fig = figure() ax = fig.add_subplot(111) a = np.zeros((100,100)) b = np.zeros((10,10)) ax.imshow(a) ax.set_autoscale_on(False) ax.contour(b) fig.canvas.draw() Running test() should result in a subplot with the view interval 0 to 99, but instead goes from 0 to 9. Is this normal? Thanks, Thomas Eric Firing wrote: > Thomas Robitaille wrote: >> Hello, >> >> I am using matplotlib to show an image using: >> >> fig = figure() >> ax = fig.add_subplot(111) >> ax.imshow(image) >> >> After doing this, I want to find the contours for a different image >> (with different dimensions), but I do not want to interact with the >> current figure or axes, I just want to retrieve the set of >> LineCollection objects for the contours. The issue is that if I do >> >> c = contour(image2) >> >> the contours are stored inside c, but at the same time they are >> plotted in the current figure. If I use >> >> ax.contour(image2) >> >> then the contours are not plotted immediately, but the view interval >> has already been changed inside ax. > > The workaround for now may be to call ax.set_autoscale_on(False) before > your call to ax.contour. You could also save the datalim before and > restore them afterwards. > > This sort of request has come up before, though, and the longer-term > solution might be some refactoring in contour.py. As it is, everything > is done when the ContourSet is instantiated; one does not have the > option of simply calculating the contours, for example. > > Eric > >> >> So essentially, I am wondering if it is possible to retrieve a set of >> LineCollection objects without acting in any way on the current >> figure/axes. > >> >> Thanks for any help, >> >> Thomas >> >> ------------------------------------------------------------------------------ >> >> Open Source Business Conference (OSBC), March 24-25, 2009, San >> Francisco, CA >> -OSBC tackles the biggest issue in open source: Open Sourcing the >> Enterprise >> -Strategies to boost innovation and cut costs with open source >> participation >> -Receive a $600 discount off the registration fee with the source >> code: SFAD >> http://p.sf.net/sfu/XcvMzF8H >> _______________________________________________ >> Matplotlib-users mailing list >> Mat...@li... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |
|
From: Eric F. <ef...@ha...> - 2009-02-22 22:45:50
|
Thomas Robitaille wrote: > Hi Eric, > > Thanks for your help! Unfortunately, ax.set_autoscale_on(False) does not > work - I had already tried this before unsuccessfully. Consider the > following: > > from pylab import * > import numpy as np > > def test(): > fig = figure() > ax = fig.add_subplot(111) > a = np.zeros((100,100)) > b = np.zeros((10,10)) > ax.imshow(a) > ax.set_autoscale_on(False) > ax.contour(b) > fig.canvas.draw() > > Running test() should result in a subplot with the view interval 0 to > 99, but instead goes from 0 to 9. > > Is this normal? On my system, it does go from 0-99. What mpl version are you using? I made the change to using autoscale_view in the ContourSet initializer, which obeys the setting by set_autoscale_on, on November 17. Prior to that, xlim and ylim were being set directly, so the workaround if you have an earlier version would be to save those values (using ax.get_xlim(), ax.get_ylim()) and then restore them with ax.set_xlim etc. Eric > > Thanks, > > Thomas > > Eric Firing wrote: >> Thomas Robitaille wrote: >>> Hello, >>> >>> I am using matplotlib to show an image using: >>> >>> fig = figure() >>> ax = fig.add_subplot(111) >>> ax.imshow(image) >>> >>> After doing this, I want to find the contours for a different image >>> (with different dimensions), but I do not want to interact with the >>> current figure or axes, I just want to retrieve the set of >>> LineCollection objects for the contours. The issue is that if I do >>> >>> c = contour(image2) >>> >>> the contours are stored inside c, but at the same time they are >>> plotted in the current figure. If I use >>> >>> ax.contour(image2) >>> >>> then the contours are not plotted immediately, but the view interval >>> has already been changed inside ax. >> >> The workaround for now may be to call ax.set_autoscale_on(False) before >> your call to ax.contour. You could also save the datalim before and >> restore them afterwards. >> >> This sort of request has come up before, though, and the longer-term >> solution might be some refactoring in contour.py. As it is, everything >> is done when the ContourSet is instantiated; one does not have the >> option of simply calculating the contours, for example. >> >> Eric >> >>> >>> So essentially, I am wondering if it is possible to retrieve a set of >>> LineCollection objects without acting in any way on the current >>> figure/axes. >> >>> >>> Thanks for any help, >>> >>> Thomas >>> >>> ------------------------------------------------------------------------------ >>> >>> >>> Open Source Business Conference (OSBC), March 24-25, 2009, San >>> Francisco, CA >>> -OSBC tackles the biggest issue in open source: Open Sourcing the >>> Enterprise >>> -Strategies to boost innovation and cut costs with open source >>> participation >>> -Receive a $600 discount off the registration fee with the source >>> code: SFAD >>> http://p.sf.net/sfu/XcvMzF8H >>> _______________________________________________ >>> Matplotlib-users mailing list >>> Mat...@li... >>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> |
|
From: Thomas R. <tho...@gm...> - 2009-02-22 22:47:55
|
Hi Eric, I'm using matplotlib 0.98 (which comes with the Enthought distribution) so that would explain why there was an issue. Thanks for your help! Thomas Eric Firing wrote: > Thomas Robitaille wrote: >> Hi Eric, >> >> Thanks for your help! Unfortunately, ax.set_autoscale_on(False) does >> not work - I had already tried this before unsuccessfully. Consider >> the following: >> >> from pylab import * >> import numpy as np >> >> def test(): >> fig = figure() >> ax = fig.add_subplot(111) >> a = np.zeros((100,100)) >> b = np.zeros((10,10)) >> ax.imshow(a) >> ax.set_autoscale_on(False) >> ax.contour(b) >> fig.canvas.draw() >> >> Running test() should result in a subplot with the view interval 0 to >> 99, but instead goes from 0 to 9. >> >> Is this normal? > > On my system, it does go from 0-99. What mpl version are you using? I > made the change to using autoscale_view in the ContourSet initializer, > which obeys the setting by set_autoscale_on, on November 17. Prior to > that, xlim and ylim were being set directly, so the workaround if you > have an earlier version would be to save those values (using > ax.get_xlim(), ax.get_ylim()) and then restore them with ax.set_xlim etc. > > Eric > >> >> Thanks, >> >> Thomas >> >> Eric Firing wrote: >>> Thomas Robitaille wrote: >>>> Hello, >>>> >>>> I am using matplotlib to show an image using: >>>> >>>> fig = figure() >>>> ax = fig.add_subplot(111) >>>> ax.imshow(image) >>>> >>>> After doing this, I want to find the contours for a different image >>>> (with different dimensions), but I do not want to interact with the >>>> current figure or axes, I just want to retrieve the set of >>>> LineCollection objects for the contours. The issue is that if I do >>>> >>>> c = contour(image2) >>>> >>>> the contours are stored inside c, but at the same time they are >>>> plotted in the current figure. If I use >>>> >>>> ax.contour(image2) >>>> >>>> then the contours are not plotted immediately, but the view interval >>>> has already been changed inside ax. >>> >>> The workaround for now may be to call ax.set_autoscale_on(False) before >>> your call to ax.contour. You could also save the datalim before and >>> restore them afterwards. >>> >>> This sort of request has come up before, though, and the longer-term >>> solution might be some refactoring in contour.py. As it is, everything >>> is done when the ContourSet is instantiated; one does not have the >>> option of simply calculating the contours, for example. >>> >>> Eric >>> >>>> >>>> So essentially, I am wondering if it is possible to retrieve a set of >>>> LineCollection objects without acting in any way on the current >>>> figure/axes. >>> >>>> >>>> Thanks for any help, >>>> >>>> Thomas >>>> >>>> ------------------------------------------------------------------------------ >>>> >>>> >>>> Open Source Business Conference (OSBC), March 24-25, 2009, San >>>> Francisco, CA >>>> -OSBC tackles the biggest issue in open source: Open Sourcing the >>>> Enterprise >>>> -Strategies to boost innovation and cut costs with open source >>>> participation >>>> -Receive a $600 discount off the registration fee with the source >>>> code: SFAD >>>> http://p.sf.net/sfu/XcvMzF8H >>>> _______________________________________________ >>>> Matplotlib-users mailing list >>>> Mat...@li... >>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >>> > |