Hi Eric,
Thanks for your help, I'm still really new to python and matplotlib. I've
got my labels defined but now I'm having another problem with the
formatting.
I'm doing -
CS1.level=[14.07, 14.27]
plt.clabel(CS1,CS1.level[::2],inline=True,fmt='OIII',fontize=14)
Where I get a type error that says that not all string arguments are
getting converted during formatting. This is the full error,
Traceback (most recent call last):
File "ContourAttempt.py", line 81, in <module>
plt.clabel(CS1,CS1.level[::2],inline=True,fmt='OIII',fontize=14) #
Something wrong with formmating
File "/Users/alexavillaume/src/matplotlib/lib/matplotlib/pyplot.py", line
2176, in clabel
ret = ax.clabel(CS, *args, **kwargs)
File "/Users/alexavillaume/src/matplotlib/lib/matplotlib/axes.py", line
7326, in clabel
return CS.clabel(*args, **kwargs)
File "/Users/alexavillaume/src/matplotlib/lib/matplotlib/contour.py",
line 217, in clabel
self.labels(inline,inline_spacing)
File "/Users/alexavillaume/src/matplotlib/lib/matplotlib/contour.py",
line 624, in labels
lw = self.get_label_width(lev, self.labelFmt, fsize)
File "/Users/alexavillaume/src/matplotlib/lib/matplotlib/contour.py",
line 284, in get_label_width
lev = self.get_text(lev, fmt)
File "/Users/alexavillaume/src/matplotlib/lib/matplotlib/contour.py",
line 344, in get_text
return fmt%lev
TypeError: not all arguments converted during string formatting
On Wed, Feb 15, 2012 at 10:34 AM, Eric Firing <efir...@hawaii.edu> wrote:
> 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
>
------------------------------------------------------------------------------
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