【发布时间】:2020-11-11 19:23:40
【问题描述】:
我不明白为什么这么难,但我不知道该怎么做。如果我绘制了多条线或点并想清除其中一条,那该怎么做?其他帖子指向remove(),但这不适用于我的情况。见例子:
Python 2.7.5 (default, Apr 2 2020, 13:16:51)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>>
>>> plt.ion()
>>> x = np.arange(100.) / 99
>>> y = np.sin(x)
>>> fig, ax = plt.subplots()
>>> h = ax.plot(x, y)
>>> h.remove()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: remove() takes exactly one argument (0 given)
【问题讨论】:
-
可能你想要
h, = ax.plot(x, y)因为plot()返回一个列表(包含一个元素)。见matplotlib 2d line line,=plot comma meaning
标签: python matplotlib