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()