add Legend to to a plot i'll save

I guys, i can’t add a legend to a plot i’m saving

The plotting code is the one below:

plt.plot(x, y_1, ‘b’, x, y_2, ‘r’, x, y_3, ‘g’)

blue_patch = mpatches.Patch(color=‘blue’, label=self.y_ok[0])

red_patch = mpatches.Patch(color=‘red’, label=self.y_ok[1])

green_patch = mpatches.Patch(color=‘green’, label=self.y_ok[2])

plt.legend(handles=[blue_patch])

plt.xlabel(self.x_ok)

plt.ylabel(self.y_ok[0] + ’ ’ +self.y_ok[1] + ’ ’ + self.y_ok[2])

plt.xlim((self.axisScale[0],self.axisScale[1]))

plt.ylim((self.axisScale[2],self.axisScale[3]))

``

I try to add the legend how you can see, but i get a warning message and the figure saved hasn’t got the legend

Could you help me?

It would be easier for someone to help you if you provide the warning
message.

Rich

···

On Sun, 5 Oct 2014, Andrea Mastrangelo wrote:

... but i get a warning message

Could you help me?

excuse me, i don’t have the message and now i cut this lines of code

it was something like: pot hasn’t attribute ‘legend’

and then, after some modifies the warning was about patch

it wasn’t an error because the file has been saved, but without legend

···

Il giorno domenica 5 ottobre 2014 17:25:25 UTC+2, fuzzydoc ha scritto:

On Sun, 5 Oct 2014, Andrea Mastrangelo wrote:

… but i get a warning message

Could you help me?

It would be easier for someone to help you if you provide the warning

message.

Rich

this was the second warning, it’s made by an other file.py, but it is the same:

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py:4486: UserWarning: No labeled objects found. Use label=‘…’ kwarg on individual plots.

warnings.warn("No labeled objects found. "

···

Il giorno domenica 5 ottobre 2014 18:02:13 UTC+2, Andrea Mastrangelo ha scritto:

excuse me, i don’t have the message and now i cut this lines of code

it was something like: pot hasn’t attribute ‘legend’

and then, after some modifies the warning was about patch

it wasn’t an error because the file has been saved, but without legend

Il giorno domenica 5 ottobre 2014 17:25:25 UTC+2, fuzzydoc ha scritto:

On Sun, 5 Oct 2014, Andrea Mastrangelo wrote:

… but i get a warning message

Could you help me?

It would be easier for someone to help you if you provide the warning

message.

Rich

A) You should not ask MPL questions in a wxPython forum

B) Do you use mpl 1.3.1 (very likely, because mpl 1.4.0 is still very fresh)?

In that case this will not work (there is also no mentioning of this syntax in the 1.3.1 docs).
You can use instead
plt.legend([blue_patch], [self.y_ok[0]])

``

···

On Sunday, October 5, 2014 4:46:54 PM UTC+2, Andrea Mastrangelo wrote:

I guys, i can’t add a legend to a plot i’m saving

Sorry for the mistake, I didn’t think about the wx, absentmindedly i though it was a python forum.

Thank you for the assistance, i kept the syntax in a forum where they didn’t say it works only with new library. I will check the difference and then i think i’ll download new versioni!

Thank you very much

···

Il giorno lunedì 6 ottobre 2014 10:10:03 UTC+2, nepix32 ha scritto:

On Sunday, October 5, 2014 4:46:54 PM UTC+2, Andrea Mastrangelo wrote:

I guys, i can’t add a legend to a plot i’m saving

A) You should not ask MPL questions in a wxPython forum

B) Do you use mpl 1.3.1 (very likely, because mpl 1.4.0 is still very fresh)?

In that case this will not work (there is also no mentioning of this syntax in the 1.3.1 docs).
You can use instead
plt.legend([blue_patch], [self.y_ok[0]])

``