SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Magnus B. <mag...@go...> - 2009年06月30日 10:39:11
Hello,
I know how to remove a line from an axes. But a I also want to remove the
label of the line from the legend of the axes.
In the sample code you can see two labels in the legend, while there is only
one line in the axes left.
import numpy as N
from matplotlib.pyplot import *
x = N.linspace(-10,10,201)
ax = figure().add_subplot(111)
ax.plot(x, x**2, label="$x^2$")
ax.plot(x, x**3, label="$x^3$")
ax.legend()
ax.lines[0].remove()
show()
Regards
Magnus
From: C L. <ch...@na...> - 2009年06月30日 16:57:19
Try calling legend() again once you've changed the lines; in ipython - 
pylab, this
x = linspace(-10, 10, 101)
sub = subplot(111)
plot(x, x**2, label="x^2")
plot(x, x**3, label="x^3")
legend() #Two lines, two legend entries
sub.lines[0].remove() #One line, two legend entries
sub.get_lines()
legend() #One line, one legend entry
works for me.
&C
On Jun 30, 2009, at 2:39 AM, Magnus Benjes wrote:
> Hello,
>
> I know how to remove a line from an axes. But a I also want to 
> remove the label of the line from the legend of the axes.
>
> In the sample code you can see two labels in the legend, while there 
> is only one line in the axes left.
>
>
> import numpy as N
> from matplotlib.pyplot import *
>
> x = N.linspace(-10,10,201)
> ax = figure().add_subplot(111)
> ax.plot(x, x**2, label="$x^2$")
> ax.plot(x, x**3, label="$x^3$")
> ax.legend()
> ax.lines[0].remove()
> show()
>
>
> Regards
> Magnus
> ------------------------------------------------------------------------------
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Chloe Lewis
Graduate student, Amundson Lab
Division of Ecosystem Sciences, ESPM
University of California, Berkeley
137 Mulford Hall - #3114
Berkeley, CA 94720-3114
ch...@na...
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /