Discussion:
add Legend to to a plot i'll save
Andrea Mastrangelo
2014-10-05 14:46:54 UTC
Permalink
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?
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Rich Shepard
2014-10-05 15:25:20 UTC
Permalink
... 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
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andrea Mastrangelo
2014-10-05 16:02:13 UTC
Permalink
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
Post by Rich Shepard
... 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
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andrea Mastrangelo
2014-10-05 16:11:58 UTC
Permalink
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
Post by Andrea Mastrangelo
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
Post by Rich Shepard
... 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
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
nepix32
2014-10-06 08:10:03 UTC
Permalink
Post by Andrea Mastrangelo
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 <http://matplotlib.org/1.3.1/users/legend_guide.html>).
You can use instead
plt.legend([blue_patch], [self.y_ok[0]])
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andrea Mastrangelo
2014-10-06 20:38:15 UTC
Permalink
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
Post by nepix32
Post by Andrea Mastrangelo
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
<http://matplotlib.org/1.3.1/users/legend_guide.html>).
You can use instead
plt.legend([blue_patch], [self.y_ok[0]])
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...