kettlepot
kettlepot

Reputation: 11011

Delete lines in matplotlib

I need to delete all the lines on a subplot, to then redraw them (i'm making a redraw function to be used when i add/remove some lines) How do I do it?

Upvotes: 3

Views: 8234

Answers (2)

ndrwnaguib
ndrwnaguib

Reputation: 6115

ax.lines is just a Python list

ax = plt.gca()
ax.lines.clear()

Upvotes: 0

Steve Tjoa
Steve Tjoa

Reputation: 61024

If you have the Axes object stored, you reference each line by the lines member:

ax = fig.add_subplot(111)
ax.plot(line one)
ax.plot(line two)
# plot
ax.lines.pop(0) # removes the first line
# plot again

Upvotes: 6

Related Questions