Savefig bug with Patches

Dear All,

I came across this peculiar bug when using patches together with savefig.

I first want to display the contour plot of the vector potentials in a
electrical machine, and the the contour plot of the flux density.

If I first define the patches (for the yoke and the magnets) and then
the first contour plot (for the vector potentials) and then, using the
same patch definitions, the second contour plot (for the flux density)

...
#Patch definitions
inner_yoke=Wedge(...)
outer_yoke=Wedge(...)
inner_N_magnet=Wedge(...)
outer_S_magnet=Wedge(...)
inner_S_magnet=Wedge(...)
outer_N_magnet=Wedge(...)

plt.figure(1)
CS=plt.contour(x,y,Az,40)
ax=plt.gca()
ax.add_patch(inner_yoke)
ax.add_patch(outer_yoke)
ax.add_patch(inner_N_magnet)
ax.add_patch(outer_S_magnet)
ax.add_patch(inner_S_magnet)
ax.add_patch(outer_N_magnet)
plt.savefig('Az-savefig.png')

plt.figure(2)
CS=plt.contour(x,y,Bmag,50)
CS=plt.contourf(x,y,Bmag,50)
ax=plt.gca()
ax.add_patch(inner_yoke)
ax.add_patch(outer_yoke)
ax.add_patch(inner_N_magnet)
ax.add_patch(outer_S_magnet)
ax.add_patch(inner_S_magnet)
ax.add_patch(outer_N_magnet)
plt.savefig('Bmag-savefig.png')

plt.show()

the two figures are displayed correctly on the screen, see
http://staff.ee.sun.ac.za/pjrandewijk/matplotlib/Az-snapshot.png and
http://staff.ee.sun.ac.za/pjrandewijk/matplotlib/Bmag-snapshot.png

However, if I look at the saved PNG files
http://staff.ee.sun.ac.za/pjrandewijk/matplotlib/Az-savefig.png and
http://staff.ee.sun.ac.za/pjrandewijk/matplotlib/Bmag-savefig.png the
patches on Bmag-savefig.png are all wrong. It looks as if the Patches
are on a totally different scale??

A workaround is to copy the Patch definitions before plt.figure(1) and
paste it just before plt.figure(2) but which is not a very elegant
solution as one has to define the exact same patches twice, i.e.

...
#Patch definitions - Take I
inner_yoke=Wedge(...)
outer_yoke=Wedge(...)
inner_N_magnet=Wedge(...)
outer_S_magnet=Wedge(...)
inner_S_magnet=Wedge(...)
outer_N_magnet=Wedge(...)

plt.figure(1)
CS=plt.contour(x,y,Az,40)
ax=plt.gca()
ax.add_patch(inner_yoke)
ax.add_patch(outer_yoke)
ax.add_patch(inner_N_magnet)
ax.add_patch(outer_S_magnet)
ax.add_patch(inner_S_magnet)
ax.add_patch(outer_N_magnet)
plt.savefig('Az-savefig.png')

#Exactly the same Patch definitions - Take II
inner_yoke=Wedge(...)
outer_yoke=Wedge(...)
inner_N_magnet=Wedge(...)
outer_S_magnet=Wedge(...)
inner_S_magnet=Wedge(...)
outer_N_magnet=Wedge(...)

plt.figure(2)
CS=plt.contour(x,y,Bmag,50)
CS=plt.contourf(x,y,Bmag,50)
ax=plt.gca()
ax.add_patch(inner_yoke)
ax.add_patch(outer_yoke)
ax.add_patch(inner_N_magnet)
ax.add_patch(outer_S_magnet)
ax.add_patch(inner_S_magnet)
ax.add_patch(outer_N_magnet)
plt.savefig('Bmag-savefig.png')

plt.show()

Kind regards,

Peter-Jan