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 |