On 02/15/2012 10:15 AM, Alexa Villaume wrote: > Hi Everybody, > > > I'm trying to label the contours of my contour plot following this > example - > > http://matplotlib.sourceforge.net/examples/pylab_examples/contour_label_demo.html > > > My actual code looks like this - > > > import matplotlib > > matplotlib.use('PDF') > > frompylab import* > > import numpy as np > > > # Define the surface of the plot > > metals=np.arange(-3.0, 1.1, 0.1) > > U=np.arange(-6.0, 0.25, 0.25) > > > # Create the arrays that the data will be stored in > > o3=np.zeros([25,41]) > > o2=np.zeros([25,41]) > > c3=np.zeros([25,41]) > > mg2=np.zeros([25,41]) > > c3=np.zeros([25,41]) > > si2=np.zeros([25,41]) > > s3=np.zeros([25,41]) > > > CS=plt.contourf(metals, U, o3, levels=[o3col-nsig*o3sig, > o3col+nsig*o3sig], alpha=0.50, colors='#f88534') > > CS=plt.contourf(metals, U, o2, levels=[o2col-nsig*o2sig, > o2col+nsig*o2sig], alpha=0.50, colors='#f2f34f') > > CS=plt.contourf(metals, U, c3, levels=[c3col-nsig*c3sig, > c3col+nsig*c3sig], alpha=0.50, colors='#93d3f3') > > CS=plt.contourf(metals, U, mg2, levels=[mg2col-nsig*mg2sig, > mg2col+nsig*mg2sig], alpha=0.50, colors='#ff536d') > > CS=plt.contourf(metals, U, s3, levels=[s3col-nsig*s3sig, > s3col+nsig*s3sig], alpha=0.50, colors='#83c460') > > CS=plt.contourf(metals, U, si2, levels=[si2col-nsig*si2sig, > si2col+nsig*si2sig], alpha=0.50, colors='black') > > > > # Trying to label the contours > > > fmt = {} > > strs = [ 'O III', 'O II', 'C III', 'Mg II', 'S III', 'Si II'] > > for l,s in zip(levels, strs): > > fmt[l] = s > > plt.clabel(CS,levels[::2],inline=True,fmt=fmt,fontize=14) > > > But I get an error that says that "levels" is not defined. What should I do?
Define levels! In your call to clabel, you are referencing a global "levels" which you did not define; what you did define is the levels attribute of each CS object. So probably what you want is something like: plt.clabel(CS, CS.levels[::2],inline=True,fmt=fmt,fontize=14) but you need one such call for each CS you create, if you want all of them labeled. Eric > > > Thanks! > > Alexa > > > > ------------------------------------------------------------------------------ > Virtualization& Cloud Management Using Capacity Planning > Cloud computing makes use of virtualization - but cloud computing > also focuses on allowing computing to be delivered as a service. > http://www.accelacomm.com/jaw/sfnl/114/51521223/ > > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users ------------------------------------------------------------------------------ Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users