I want to remove a specific line in a plot of multiple lines. Bellow is a given example which is not sufficient for me because it removes only the last plotted line and not
I had the same need and for me, it turned out to be tidier to add an id to the data series and remove it later by finding the series (collection) with the given id.
def add_series(x, id):
plt.plot(x, gid = id)
def remove_series(id):
for c in plt.collections: # possibly better to use: for c in plt.lines (see comment)
if c.get_gid() == id:
c.remove()