plot legend behavior & question

Thank you for the immediate and extremely helpful suggestions. Changing the string to a tuple works great, and I did not think about using the “label” keyword in plot. I think this will greatly simplify the plotting.

Thanks again for the “instant gratification”. :slight_smile:




The 2nd Law of Thermodynamics… If you think things are a mess now, JUST WAIT!

On Tue, Sep 16, 2008 at 3:28 PM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

(‘CO2’) is not a tuple but still a single string.

You may use a list [‘CO2’] or put an extra “,” to make it a tuple (‘CO2’,).

And, you may consider to use the “label” keyword with your plot command.



On Tue, Sep 16, 2008 at 5:09 PM, charles reid <charlesreid1@…287…> wrote:

Hi there -

I’m using the latest stable pylab/matplotlib (0.98.3) via OS X 10.5.4. I am

plotting a simple array of data, and I’m getting some strange behavior when

I try to add a legend to the plot.

First, the plot without the legend:


title(“Equilibrium Concentration vs. Equivalence Ratio”)

line1 = plot(phi,xeq[1])


This works fine. However, when I try to add a legend, I get an error. I

add this:


title(“Equilibrium Concentration vs. Equivalence Ratio”)

line1 = plot(phi,xeq[1])



And it gives me an error because of the second argument to f.legend:

ValueError Traceback (most recent call last)

/Users/charles/Documents/school/combustion/problem-2-52/ in


111 title("Equilibrium Concentrations vs. Equivalence Ratio")
112 line1=plot(phi,xeq[1])

–> 113 f.legend(line1,(‘CO2’),loc=(0.8,0.8))

114 show()


in legend(self, handles, labels, *args, **kwargs)

841         """
842         handles = flatten(handles)

–> 843 l = Legend(self, handles, labels, *args, **kwargs)

844         self.legends.append(l)
845         return l


in init(self, parent, handles, labels, loc, numpoints, prop, pad,

markerscale, labelsep, handlelen, handletextsep, axespad, shadow)

180         textleft = left+ self.handlelen+self.handletextsep
181         self.texts = self._get_texts(labels, textleft, top)

–> 182 self.legendHandles = self._get_handles(handles, self.texts)

184         self._drawFrame = True


in _get_handles(self, handles, texts)

246         # centered marker proxy

–> 248 for handle, label in safezip(handles, texts):

249             if self.numpoints > 1:
250                 xdata = np.linspace(left, left + self.handlelen,



in safezip(*args)

899     for i, arg in enumerate(args[1:]):
900         if len(arg) != Nx:

–> 901 raise ValueError(_safezip_msg % (Nx, i+1, len(arg)))

902     return zip(*args)

ValueError: In safezip, len(args[0])=1 but len(args[1])=3

WARNING: Failure executing file: <>

I don’t understand why this doesn’t work, because I should be able to give a

label of arbitrary length. It doesn’t work when I replace single quotes

with double quotes, either. But I change the length to 1, like it wants:


title(“Equilibrium Concentrations vs. Equivalence Ratio”)




Which creates a plot, with a legend, but when I move the mouse over the

plot, it has the “thinking” cursor (hourglass). I can’t close the window

using the buttons in the upper left hand corner, I can’t close it using

close(1), and I can’t close it using close(‘all’). I end up having to run

‘killall Python’ from a command line.

I can get the plot with the legend to work, albeit with only ONE character

for the name, by running (from Python)


title(“Equilibrium Concentrations vs. Equivalence Ratio”)



(without the show() command) in the script, then running show() when the

script is done, and I don’t get the “thinking” cursor.

Note: I have also used the function figlegend() with the exact same


  1. How can I give a legend name with a length of more than 1 character?

What am I doing wrong?

  1. What is causing the behavior with the thinking cursor?

Also, ultimately I would like to make a plot with 30+ species, instead of

just CO2. Is there a way to do this other than doing the following?

line1 line2 line3 … =



Thanks ahead of time for any suggestions or hints.


This SF.Net email is sponsored by the Moblin Your Move Developer’s challenge

Build the coolest Linux based applications with Moblin SDK & win great


Grand prize is a trip for two to an Open Source event anywhere in the world

Matplotlib-users mailing list