|
From: Daniel F. <dan...@we...> - 2011-01-27 19:22:31
|
> > Dear all, > > contourset = pyplot.contour(..) > > calculates the contourset but also grabs whatever figure is currently > active *somewhere* in the entire code > and whichever scope it was created. The contours are plotted into it. > > While I could possibly live with that, I would really like to > suppress any plotting and grabbig of focus. Only the contourset > should be calculated. > > I can't find anything that describes this. Everybody wants the plot, > not me. > > I would like to avoid hte workaround to ask for the currently active > figure (if!! there is one at all), store the number, and later return > focus. Is there no switch parameter (in pyplot or for contour at > least) that turns plotting off? > > Regards > Daniel > > >> >> Hi Daniel, >> >> I'm not sure if this gets at what you're asking for, but if >> you just want the contours plotted on a figure other than the >> currently active one, grab a handle to some other axes and call >> contour from the axes itself (the parameters are the same). >> Here's what I mean: >> >> ----------- >> f,ax =plt.subplots(1,1) #grab handles to figure and axes >> # or, if you're using an older version of matplotlib, do: >> # f=plt.figure();ax=plt.subplot(1,1,1) >> >> >> f2,ax2 =plt.subplots(1,1) # "f" no longer active figure >> ... >> contourset = ax.contour(...) # draw to the old figure "f" >> ----------- >> >> You can read more about the difference between using pyplot and >> using the object-oriented api here: >> >> http://matplotlib.sourceforge.net/faq/usage_faq.html >> >> On the other hand, if you just want the contour to not show up, >> you can pass it alpha=0.0 to make it completely transparent and >> invisible (but it's still there) >> >> contourset = pyplot.contour(.., alpha=0.0) >> # later call contourset.set_alpha(1.0) to make visible again >> >> best, >> -- >> Paul Ivanov Dear Paul, no, I would like to suppress plotting entirely, avoid changing of active figure and avoid handling figures or axis completely. I m only interested in the contourset. I wonder if my post was somehow sloppy. Yes, there are work-arounds like creating a dummy figure, similar to your suggestion, and return focus to the previously active figure. But plotting takes time and memory, is not needed and requires several code lines. Once might be ok but speed and memory is important. Plotting with alpha=0 still requires figure and axis handling. So how can I switch off all figure and axis related actions and savely call contourset = contour(x,y,...) that does nothing else than return the contours? Regards Daniel |
|
From: Eric F. <ef...@ha...> - 2011-01-27 19:35:44
|
On 01/27/2011 09:21 AM, Daniel Fulger wrote: >> >> Dear all, >> >> contourset = pyplot.contour(..) >> >> calculates the contourset but also grabs whatever figure is currently >> active *somewhere* in the entire code >> and whichever scope it was created. The contours are plotted into it. >> >> While I could possibly live with that, I would really like to >> suppress any plotting and grabbig of focus. Only the contourset >> should be calculated. >> >> I can't find anything that describes this. Everybody wants the plot, >> not me. >> >> I would like to avoid hte workaround to ask for the currently active >> figure (if!! there is one at all), store the number, and later return >> focus. Is there no switch parameter (in pyplot or for contour at >> least) that turns plotting off? >> >> Regards >> Daniel >> >> >>> >>> Hi Daniel, >>> >>> I'm not sure if this gets at what you're asking for, but if >>> you just want the contours plotted on a figure other than the >>> currently active one, grab a handle to some other axes and call >>> contour from the axes itself (the parameters are the same). >>> Here's what I mean: >>> >>> ----------- >>> f,ax =plt.subplots(1,1) #grab handles to figure and axes >>> # or, if you're using an older version of matplotlib, do: >>> # f=plt.figure();ax=plt.subplot(1,1,1) >>> >>> >>> f2,ax2 =plt.subplots(1,1) # "f" no longer active figure >>> ... >>> contourset = ax.contour(...) # draw to the old figure "f" >>> ----------- >>> >>> You can read more about the difference between using pyplot and >>> using the object-oriented api here: >>> >>> http://matplotlib.sourceforge.net/faq/usage_faq.html >>> >>> On the other hand, if you just want the contour to not show up, >>> you can pass it alpha=0.0 to make it completely transparent and >>> invisible (but it's still there) >>> >>> contourset = pyplot.contour(.., alpha=0.0) >>> # later call contourset.set_alpha(1.0) to make visible again >>> >>> best, >>> -- >>> Paul Ivanov > > Dear Paul, > > no, I would like to suppress plotting entirely, avoid changing of > active figure and avoid handling figures or axis completely. > I m only interested in the contourset. I wonder if my post was > somehow sloppy. > > Yes, there are work-arounds like creating a dummy figure, similar to > your suggestion, and return focus to > the previously active figure. But plotting takes time and memory, is > not needed and requires several code lines. Once might be ok but > speed and memory is important. > Plotting with alpha=0 still requires figure and axis handling. > > So how can I switch off all figure and axis related actions and > savely call contourset = contour(x,y,...) that does nothing else than > return the contours? Look at contour.py, specifically QuadCountourSet._process_args. You will see the call to _cntr.Cntr. That is the core class, implemented in extension code. The contour generation is in the method _get_allsegs_and_allkinds, via the call to the Cntr.trace() method. You will have to put together your own function to instantiate Cntr and call Cntr.trace for each level. A major refactoring could be done to separate the calculation from the plotting, maybe by making the ContourSet into a compound artist and putting the drawing into a draw() method instead of having it called in the __init__() method. Eric > > > Regards > Daniel > |
|
From: Paul I. <piv...@gm...> - 2011-01-27 20:04:54
|
Benjamin Root, on 2011-01-27 13:04, wrote: > I believe he would rather call the core function that contour uses to > do the heavy lifting. This was something that one can do in matlab, > btw. I don't have access to the source right now. What does contour > call to perform this calculation? matplotlib.contour.QuadContourSet - which in turn uses ContourSet, and both take ax as a required argument. They use matplotlib.contour._cntr which is Daniel Fulger, on 2011-01-27 20:21, wrote: > no, I would like to suppress plotting entirely, avoid changing of > active figure and avoid handling figures or axis completely. > I m only interested in the contourset. I wonder if my post was > somehow sloppy. > > Yes, there are work-arounds like creating a dummy figure, similar to > your suggestion, and return focus to > the previously active figure. But plotting takes time and memory, is > not needed and requires several code lines. Once might be ok but > speed and memory is important. > Plotting with alpha=0 still requires figure and axis handling. > > So how can I switch off all figure and axis related actions and > savely call contourset = contour(x,y,...) that does nothing else than > return the contours? I understand better now, but as far as I could tell from poking inside the QuadContourSet code, there isn't a simple way to call the underlying machinery which generates the contours. You'll have to look at what QuadContourSet._contour_args does internally to see what what x, y, z should be, and then create a contour using C = matplotlib.contour._cntr.Cntr(x,y,z) and then for each level, do something like what QuadContourSet._get_allsegs_and_allkinds does C.trace(..) best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 |
|
From: Ian T. <ian...@gm...> - 2011-01-27 20:52:11
Attachments:
contour_test.py
|
Daniel, Following on from Eric's comments, attached is the simplest example I could come up with to do what you want. For non-filled contours, the 'segs' (last few lines of the file) should be fairly self-explanatory, and this is hopefully what you want. If you are after filled contours, you will need to understand both the 'segs' and the 'kinds' - essentially the segs comprise one or more discontinuous closed line loops and the corresponding kinds indicate how the loops are split up, a 1 being a LINETO and a 2 being a MOVETO. This can get a little awkward, and I think that sometimes you need to deal with arrays of arrays but I can't completely remember all the details. You should bear in mind that this code delves into matplotlib internals and you need to be careful as 1) it bypasses various sanity checks, 2) the underlying code could change at any point in the future (it has quite a lot in the last year for example). Otherwise, I hope it helps! Ian |