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’)
from pylab 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-nsigo3sig, o3col+nsigo3sig], alpha=0.50, colors=’#f88534’)
CS=plt.contourf(metals, U, o2, levels=[o2col-nsigo2sig, o2col+nsigo2sig], alpha=0.50, colors=’#f2f34f’)
CS=plt.contourf(metals, U, c3, levels=[c3col-nsigc3sig, c3col+nsigc3sig], alpha=0.50, colors=’#93d3f3’)
CS=plt.contourf(metals, U, mg2, levels=[mg2col-nsigmg2sig, mg2col+nsigmg2sig], 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-nsigsi2sig, si2col+nsigsi2sig], 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?
Thanks!
Alexa