From: <er...@jo...> - 2004-04-21 19:26:08
|
Dear ones, I discovered Matplotlit only yesterday, and it's great. But I've got one problem. Since I am using the GTK backend, I have to use the show() function. But I have hundreds of figures and each to be written into a file. If I put the show() at the end of my program, the machine just can't handle it. If I put the show() in a loop, then I have close the hundreds of picture windows by hand. Is there a solution to this problem? Also the Matplotlib I downloaded doesn't have the file libjpeg.dll in it. Wonder where can I get it. Looking forward to hearing some advices from you. Enjoy the day. Eric |
From: John H. <jdh...@ac...> - 2004-04-21 19:33:59
|
>>>>> "Eric" == <er...@jo...> writes: Eric> Dear ones, I discovered Matplotlit only yesterday, and it's Eric> great. But I've got one problem. Since I am using the GTK Eric> backend, I have to use the show() function. But I have Eric> hundreds of figures and each to be written into a file. If I Eric> put the show() at the end of my program, the machine just Eric> can't handle it. If I put the show() in a loop, then I have Eric> close the hundreds of picture windows by hand. Is there a Eric> solution to this problem? Yes, you want to use the Agg backend for bulk pure image generation. You don't need to use show and no GUI pops up. You can specify Agg from the command line by doing > python myscript.py -dAgg Or from within your script by doing import matplotlib matplotlib.use('Agg') from matplotlib.matlab import * plot([1,2,3]) savefig('myfile') Agg provides PNG output, which in my opinion is superior to jpeg for line art. These issues are covered in the FAQ, especially "Can I just generate images without having a window popup?" http://matplotlib.sourceforge.net/faq.html You should probably also check out http://matplotlib.sourceforge.net/tutorial.html and http://matplotlib.sourceforge.net/backends.html Good luck! JDH |
From: Peter G. <pgr...@ge...> - 2004-04-21 22:13:31
Attachments:
m1MQLarge.png
|
Hi: I attach a pcolor plot. I would like to get rid of the areas outside the larger circle and inside the smaller circle. Ideally I would like them to be white. Currently I create my plot using pcolor and then plot *lots* of white circles (for the inside) and lines (for the outside) on top, to get rid of the unwanted areas. This works but I wonder whether there is a better/faster solution. I would imagine I could set the values corresponding to the unwanted areas to some particular color before I call pcolor, but the issue is that I want those ares to be white (or other color not included in the standard palette which is used for plotting the area inside the annulus). Can this be done? Another question is in regards to showing tics in pcolor plots. In my "legend" on the right, I would like them to be visible, but they get overwritten. I suppose I could plot each manually after I do pcolor; is it how this is meant to be done? Thanks -- Peter Groszkowski Gemini Observatory Tel: +1 808 974-2509 670 N. A'ohoku Place Fax: +1 808 935-9235 Hilo, Hawai'i 96720, USA |
From: John H. <jdh...@ac...> - 2004-04-21 22:51:46
|
>>>>> "Peter" == Peter Groszkowski <pgr...@ge...> writes: Peter> Hi: I attach a pcolor plot. I would like to get rid of the Peter> areas outside the larger circle and inside the smaller Peter> circle. Ideally I would like them to be white. Currently I Peter> create my plot using pcolor and then plot *lots* of white Peter> circles (for the inside) and lines (for the outside) on Peter> top, to get rid of the unwanted areas. This works but I Peter> wonder whether there is a better/faster solution. I would Peter> imagine I could set the values corresponding to the Peter> unwanted areas to some particular color before I call Peter> pcolor, but the issue is that I want those ares to be white Peter> (or other color not included in the standard palette which Peter> is used for plotting the area inside the annulus). Can this Peter> be done? Inside the circle is easy - just set the facecolor of the circle to be white 'w', or whatever rgb tuple you want. How are you creating the circles, with plot, scatter, or instantiating your own Circle instances? Outside the circle requires implementing general clipping, which will be done but I can't say how soon right now. What backend are you using? The circles don't look antialiased so I'm guessing not agg. agg and postscript are probably the best bets for getting general clipping support first. Another question: is there a reason you are using pcolor rather than imshow? imshow will give you the same result with interpolation and dramatic performance benefits. Since you aren't using faceted shading or otherwise tweaking the pcolor rectangles, you don't gain anything by using pcolor unless you need a backend that doesn't support imshow yet (gd?) Peter> Another question is in regards to showing tics in pcolor Peter> plots. In my "legend" on the right, I would like them to be Peter> visible, but they get overwritten. I suppose I could plot Peter> each manually after I do pcolor; is it how this is meant to Peter> be done? This is an easy fix. Basically you just need to move the axis drawing to the end of the axes drawing code. Currently it is done before any before any lines or patches are drawn. Try replacing matplotlib.Axes._draw with the code below. I'll make a deal: if you contribute some code to produce the nice color legend you made, I'll try and implement general clipping! JDH def _draw(self, renderer, *args, **kwargs): "Draw everything (plot lines, axes, labels)" if not ( self.xaxis.viewlim.defined() and self.yaxis.viewlim.defined() ): self.update_viewlim() if self.axison: if self._frameon: self._axesPatch.draw(renderer) if self._image is not None: self._image.draw(renderer) for p in self._patches: p.draw(renderer) for line in self._lines: line.draw(renderer) for t in self._text: t.draw(renderer) self._title.draw(renderer) if 0: bbox_artist(self._title, renderer) # optional artists for a in self._artists: a.draw(renderer) if self._legend is not None: self._legend.draw(renderer) for table in self._tables: table.draw(renderer) if self.axison: self.xaxis.draw(renderer) self.yaxis.draw(renderer) |
From: Peter G. <pgr...@ge...> - 2004-04-23 19:13:54
|
John Hunter wrote: >>>>>> "Peter" == Peter Groszkowski <pgr...@ge...> writes: >>>>>> >>>>> > > Peter> Hi: I attach a pcolor plot. I would like to get rid of the > Peter> areas outside the larger circle and inside the smaller > Peter> circle. Ideally I would like them to be white. Currently I > Peter> create my plot using pcolor and then plot *lots* of white > Peter> circles (for the inside) and lines (for the outside) on > Peter> top, to get rid of the unwanted areas. This works but I > Peter> wonder whether there is a better/faster solution. I would > Peter> imagine I could set the values corresponding to the > Peter> unwanted areas to some particular color before I call > Peter> pcolor, but the issue is that I want those ares to be white > Peter> (or other color not included in the standard palette which > Peter> is used for plotting the area inside the annulus). Can this > Peter> be done? > > Inside the circle is easy - just set the facecolor of the circle to be > white 'w', or whatever rgb tuple you want. How are you creating the > circles, with plot, scatter, or instantiating your own Circle > instances? > > I'm creating circles using the plot command, just transform my r and theta to x and y. It turned out that this is trivial using the fill command - one liner. I haven't used fill before but it seems very handy for this sort of thing. > Outside the circle requires implementing general clipping, which will > be done but I can't say how soon right now. > Again did it with fill - two lines. > What backend are you > using? The circles don't look antialiased so I'm guessing not agg. > agg and postscript are probably the best bets for getting general > clipping support first. > > > I have been using GD. You may remember a while ago, when I had some major performance issues (which turned out was because AA was on by default) you did a little analysis and concluded that GD is the fastest, even thought one needs to turn AA off. For most of my plotting, performance is crucial so I simply stuck with it. Another issue is the fact that Agg does not have a write-to-stream feature implemented. > Another question: is there a reason you are using pcolor rather than > imshow? imshow will give you the same result with interpolation and > dramatic performance benefits. Since you aren't using faceted shading > or otherwise tweaking the pcolor rectangles, you don't gain anything > by using pcolor unless you need a backend that doesn't support imshow > yet (gd?) > > Yes. Was using GD. Did some testing with Agg, and in the imshow plots do look quite nice. When write-to-stream feature gets added (or get around to adding it myself) will use imshow() instead of pcolor(). > Peter> Another question is in regards to showing tics in pcolor > Peter> plots. In my "legend" on the right, I would like them to be > Peter> visible, but they get overwritten. I suppose I could plot > Peter> each manually after I do pcolor; is it how this is meant to > Peter> be done? > > This is an easy fix. Basically you just need to move the axis drawing > to the end of the axes drawing code. Currently it is done before any > before any lines or patches are drawn. Try replacing > matplotlib.Axes._draw with the code below. > > > Yeah, this worked nice. > I'll make a deal: if you contribute some code to produce the nice > color legend you made, I'll try and implement general clipping! > > Well... to be honest, with your **magic** fill command I don't really need 'general clipping' and would prefer write-to-stream for Agg.. so I propose you implement whichever more people would find useful. The code is rather trivial, and works great in my case (specific fig dimensions and layout), but one would probably have to think about the details of having it as a part of the core library and work for general cases; some of the numbers when calling axes() might have to be adjusted. So an example might be: #!/usr/bin/python import sys, os from matplotlib.matlab import * from matplotlib.ticker import NullLocator figure(1, figsize=(6,5), facecolor='w', edgecolor='w', dpi=150) #This size woks best for me. mainAxes=axes([0.125, 0.05, 0.655, 0.83], frameon=0) xi=linspace(-4,4,200); yi=linspace(-4,4,200); [Xi,Yi]=meshgrid(xi,yi); Zi=fromfunction(lambda i,j: (i+j)%40, (200,200)) #Some dummy data pcolor(Xi, Yi, Zi, shading='flat') #Could use imshow() #Remove the x and y ticks. Is this how it's done in 0.53? mainAxes.xaxis.set_major_locator(NullLocator()) mainAxes.yaxis.set_major_locator(NullLocator()) legendAxes=axes([0.85, 0.05, 0.05, 0.83]) #Essentially want to make sure that the smallest/largest values on the legend correspond to the smallest/largest values in Zi yy=ravel(Zi) ymin,ymax=floor(min(yy)), ceil(max(yy)) dy=float(abs((ymax)-(ymin)))/256.0 x=arange(0,50) #When this is smaller, imshow() does not display the legend properly, but for pcolor could just do arange(0,2) y=arange(ymin,ymax,dy) Xi,Yi=meshgrid(x,y) pcolor(Xi, Yi, Yi, shading='flat') #Again could use imshow() legendAxes.xaxis.set_major_locator(NullLocator()) legendAxes.set_ylim([ymin,ymax]) show() -- Peter Groszkowski Gemini Observatory Tel: +1 808 974-2509 670 N. A'ohoku Place Fax: +1 808 935-9235 Hilo, Hawai'i 96720, USA |
From: Peter G. <pgr...@ge...> - 2004-04-24 01:48:07
|
The pcolor_demo.py and pcolor_demo2.py show somewhat different results: ------------ from matplotlib.matlab import * def fun3(x,y): return (1- x/2 + x**5 + y**3)*exp(-x**2-y**2) xi=arange(-3.0, 3.0, 0.05) yi=arange(-3.0, 3.0, 0.05) [Xi,Yi]=meshgrid(xi,yi); Zi=fun3(Xi,Yi) if 1: cMap = ColormapJet(256) imshow(Zi, cMap) gca().set_image_extent(-3, 3, -3, 3) else: pcolor(Xi, Yi, Zi, shading='flat') show() ------------- The y axis seem to be inverted on imshow when compared to pcolor. Was this intentional? |