On Wednesday, June 30, 2010 06:24:12 pm Philippe Crave wrote:
> Hello,
> 
> I have a subplot with 4 lines.
> I display the legend.
> I can remove a line easily with something like del(self.ax.lines[n]).
> But how can I remove the line in the legend ?
> 
> I found that I can remove all the lines, add news ones, but all the
> lines (new and deleted) remain in the legend.

Hi Philippe,

I think you simply can set up a new legend replacing the old one. I attached 
an example script of that.

Kind regards,
Matthias
import numpy as np
from matplotlib import pyplot as plt

x = np.linspace(0.0, 2*np.pi, 100)

plt.ion()
ax = plt.gca()
ax.plot(x, +np.sin(x), label='sin(x)')
ax.plot(x, +np.cos(x), label='cos(x)')
ax.plot(x, -np.sin(x), label='-sin(x)')
ax.plot(x, -np.cos(x), label='-cos(x)')

plt.legend()

raw_input("press >Enter< to continue -> ")

# remove some lines
ax.lines.pop(-1)
ax.lines.pop(2)

# set up a new legend
plt.legend()

plt.ioff()
plt.show()
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to