On Fri, Jul 9, 2010 at 6:28 AM, Johannes Röhrs <johanne...@met.no> wrote: > I have some troubles updating a contour plot. I reduced my code to a simple > example to reproduce the problem: > > [code] > from pylab * > import scipy as sp > > x=sp.arange(0,2*sp.pi,0.1) > X,Y=sp.meshgrid(x,x) > f1=sp.sin(X)+sp.sin(Y) > f2=sp.cos(X)+sp.cos(Y) > > figure() > C=contourf(f1) > show() > > C.set_array(f2) > draw() > [\code] > > What do I need to do to update an existing contour plot with new data?
The set_array() method (I think) only impacts the colormapping information for contourf, and even then doesn't appear to update. What you need to do is make a new contour plot and remove the old one, especially if you need to change the underlying contoured data. This should be as easy as C.remove(), but for some reason, this doesn't exist (I'll go add it in a minute). So instead, you need to do the following: import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 2 * np.pi, 0.1) X,Y = np.meshgrid(x,x) f1 = np.sin(X) + np.sin(Y) f2 = np.cos(X) + np.cos(Y) plt.figure() C = plt.contourf(f1) plt.show() for coll in C.collections: plt.gca().collections.remove(coll) C = plt.contourf(f2) plt.draw() Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users