From: Andrew S. <str...@as...> - 2004-03-05 12:06:05
|
G'day all! I'm back to using matplotlib after a few months away. I'm very impressed with the recent progress! I often plot the instantaneous variance of repeated recordings made under the same conditions using a shaded area to surround the mean. I'm trying to find a way to do this with matplotlib. Included below is a "filly" (fill y) function I wrote to attempt to do this. It doesn't quite work yet, and I'd like some help. (BTW, I don't know of how this would be done in Matlab, so if there's a more compatible way, I'd be happy to change the approach.) 1) How do I make the data fill the axes automatically, such as the "plot" function? 2) Is it a bug that the polygon is not filled, or am I missing something? I've only tried this in the PS backend -- I'm having troubles with the others at the moment. Also, this is using the version of matplotlib I checked out with CVS. This version fails to build the agg backend with: running build_py package init file 'ttfquery/__init__.py' not found (or not a regular file) package init file 'FontTools/__init__.py' not found (or not a regular file) package init file 'FontTools/fontTools/__init__.py' not found (or not a regular file) package init file 'FontTools/fontTools/encodings/__init__.py' not found (or not a regular file) error: package directory 'FontTools/fontTools/misc' does not exist Cheers! Andrew -=-=-=-=-=-=-= filly.py -=-=-=-=-=-=-=-= from matplotlib.matlab import * from matplotlib.patches import Rectangle, Polygon def filly(x,y1,y2,**kwargs): ax = gca() xy = [] for xi, yi in zip(x,y1): xy.append( (xi,yi) ) for xi, yi in zip(x[::-1],y2[::-1]): xy.append( (xi,yi) ) xy.append( xy[0] ) polygon = Polygon( ax.dpi, ax.bbox, xy, transx = ax.xaxis.transData, # what does this do? transy = ax.yaxis.transData, # and this?? **kwargs) ax.add_patch(polygon) return polygon figure(1) t = arange(0.0, 1.0, 0.01) s_mean = 0.5*sin(2*2*pi*t) s_lo = s_mean-0.1 s_hi = s_mean+0.1 #plot(t,s_mean,'k') filly(t,s_lo,s_hi,fill=1,facecolor='g') gca().xaxis.autoscale_view() # why doesn't this help? gca().yaxis.autoscale_view() savefig('filly') #show() |
From: John H. <jdh...@ac...> - 2004-03-06 16:28:45
|
>>>>> "Andrew" == Andrew Straw <str...@as...> writes: Andrew> G'day all! I'm back to using matplotlib after a few Andrew> months away. I'm very impressed with the recent progress! Thanks. It's good to see you back around in these parts :-) Andrew> I often plot the instantaneous variance of repeated Andrew> recordings made under the same conditions using a shaded Andrew> area to surround the mean. I'm trying to find a way to do Andrew> this with matplotlib. Included below is a "filly" (fill Andrew> y) function I wrote to attempt to do this. It doesn't Andrew> quite work yet, and I'd like some help. (BTW, I don't Andrew> know of how this would be done in Matlab, so if there's a Andrew> more compatible way, I'd be happy to change the approach.) Andrew> 1) How do I make the data fill the axes automatically, Andrew> such as the "plot" function? Andrew> 2) Is it a bug that the polygon is not filled, or am I Andrew> missing something? Andrew> I've only tried this in the PS backend -- I'm having Andrew> troubles with the others at the moment. Also, this is Andrew> using the version of matplotlib I checked out with CVS. Andrew> This version fails to build the agg backend with: Andrew> running build_py package init file 'ttfquery/__init__.py' Andrew> not found (or not a regular file) package init file Andrew> 'FontTools/__init__.py' not found (or not a regular file) Andrew> package init file 'FontTools/fontTools/__init__.py' not Andrew> found (or not a regular file) package init file Andrew> 'FontTools/fontTools/encodings/__init__.py' not found (or Andrew> not a regular file) error: package directory Andrew> 'FontTools/fontTools/misc' does not exist I won't get a chance to look at your fill code til Monday (which BTW is something I've been wanting to add for a while), but the main problem here is that CVS doesn't have a complete version of the FontTools* and ttf* that are needed to build from src. The 0.51 release is actually quite up to date and you would probably be best off just working in that tree for now. vis-a-vis FontTools and ttfquery - an increasing number of matplotlib backends need ttf font finding capabilitlities which FontTools and ttfquery provide. However, they are big and a pain to install and Paul Barrett has been working on a replacement. At one point I added them to CVS since I was distributing them with matplotlib but thought twice about it and tried to remove them. However despite multiple attempts I have not been able to get them out of CVS (a free beer to anyone with commit privs who can purge these bastards). No in a nutshell there is an incomplete version of FontTools and ttfquery in CVS. If you want to build from CVS, copy the agg, FontTools* and ttfquery dirs/files from the 0.51 src distro into the CVS tree and build from there. This will all be cleared up in a few weeks time. JDH |
From: Andrew S. <str...@as...> - 2004-03-07 04:22:03
|
John Hunter wrote: > Andrew> Also, this is > Andrew> using the version of matplotlib I checked out with CVS. > Andrew> This version fails to build the agg backend with: > > Andrew> running build_py package init file 'ttfquery/__init__.py' > Andrew> not found (or not a regular file) package init file > Andrew> 'FontTools/__init__.py' not found (or not a regular file) > Andrew> package init file 'FontTools/fontTools/__init__.py' not > Andrew> found (or not a regular file) package init file > Andrew> 'FontTools/fontTools/encodings/__init__.py' not found (or > Andrew> not a regular file) error: package directory > Andrew> 'FontTools/fontTools/misc' does not exist > > I won't get a chance to look at your fill code til Monday (which BTW > is something I've been wanting to add for a while), but the main > problem here is that CVS doesn't have a complete version of the > FontTools* and ttf* that are needed to build from src. The 0.51 > release is actually quite up to date and you would probably be best > off just working in that tree for now. vis-a-vis FontTools and > ttfquery - an increasing number of matplotlib backends need ttf font > finding capabilitlities which FontTools and ttfquery provide. > However, they are big and a pain to install and Paul Barrett has been > working on a replacement. At one point I added them to CVS since I > was distributing them with matplotlib but thought twice about it and > tried to remove them. However despite multiple attempts I have not > been able to get them out of CVS (a free beer to anyone with commit > privs who can purge these bastards). No in a nutshell there is an > incomplete version of FontTools and ttfquery in CVS. This is one of the downsides of CVS; it doesn't deal with directories very well (or at all). A SourceForge support request would be required for one of their admins to go into CVSROOT and manually do this. What's wrong with distributing them via CVS, at least while they're distributed in the officially released matplotlib sources? It would made things a bit cleaner for those willing to live on the bleeding edge. (Then again, I suppose those willing to live on the bleeding edge are probably also be happy copy a few directories around, too. At least as long as we know what to do.) > If you want to build from CVS, copy the agg, FontTools* and ttfquery > dirs/files from the 0.51 src distro into the CVS tree and build from > there. Works like a charm! Cheers! Andrew |
From: John H. <jdh...@ac...> - 2004-03-08 19:15:37
|
>>>>> "Andrew" == Andrew Straw <str...@as...> writes: Andrew> 2) Is it a bug that the polygon is not filled Yes, none of the rest of the drawing interface uses Polygon so I hadn't noticed it. In patches.py, replace line 330 with renderer.draw_polygon(gc, rgbFace, vertices) Below is your (modified) original script, with comments that answer your questions. With the patch above and some changes I made, it now works (cool). It would be nice to figure out how to properly include this in the regular API. JDH from matplotlib.matlab import * from matplotlib.patches import Rectangle, Polygon def filly(x,y1,y2,**kwargs): ax = gca() xy = [] for xi, yi in zip(x,y1): xy.append( (xi,yi) ) for xi, yi in zip(x[::-1],y2[::-1]): xy.append( (xi,yi) ) xy.append( xy[0] ) # see # http://matplotlib.sourceforge.net/matplotlib.transforms.html # for information on the new transform system. You can place # objects in a variety of coord systems, most freqeuntly data or # axes. data are the old-style coords you are used to. axes # coords are normalized on a 0-1 scale. The xaxis and yaxis # instances store default transforms so you can easily create new # objects in either coord system. ax.xaxis.transData transforms # data units to display units for the xaxis. ax.xaxis.transAxis # transforms axis units to display units. You have done it right # here. polygon = Polygon( ax.dpi, ax.bbox, xy, transx = ax.xaxis.transData, # what does this do? transy = ax.yaxis.transData, # and this?? **kwargs) ax.add_patch(polygon) return polygon figure(1) t = arange(0.0, 1.0, 0.01) s_mean = 0.5*sin(2*2*pi*t) s_lo = s_mean-0.1 s_hi = s_mean+0.1 #plot(t,s_mean,'k') filly(t,s_lo,s_hi,fill=1,facecolor='g') # I haven't decided yet on how to handle autoscaling with patches # since there is no efficient easy way to get the patch's extent in # data coords. Instead, I update the datalim manually in plot # commands that use pataches gca().xaxis.datalim.update((min(t), max(t))) gca().yaxis.datalim.update((min(s_lo), max(s_hi))) # now this should work since the data lim are updated gca().xaxis.autoscale_view() gca().yaxis.autoscale_view() #savefig('filly') show() |