删除 matplotlib 中的行

Gab*_*lli 2 matplotlib

我需要删除子图上的所有线条,然后重绘它们(我正在制作一个重绘函数,以便在添加/删除一些线条时使用)我该怎么做?

Ste*_*joa 5

如果您Axes存储了对象,则通过lines成员引用每一行:

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