我怎样才能删除一个流线图 https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.streamplot.html来自 Matplotlib 绘图而不清除所有内容(i.e.不使用plt.cla()
or plt.clf()
)?
plt.streamplot() https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.streamplot.html返回一个StreamplotSet
(streams
在下面的示例中),其中包含流线(.lines
)和箭头(.arrows
).
Calling streams.lines.remove()
按预期删除流线。
但是,我找不到删除箭头的方法:stream.arrows.remove()
提出一个NotImplementedError
, and stream.arrows.set_visible(False)
没有影响。
import matplotlib.pyplot as plt
import numpy as np
# Generate streamplot data
x = np.linspace(-5, 5, 10)
y = np.linspace(-5, 5, 10)
u, v = np.meshgrid(x, y)
# Create streamplot
streams = plt.streamplot(x, y, u, v)
# Remove streamplot
streams.lines.remove() # Removes the stream lines
streams.arrows.set_visible(False) # Does nothing
streams.arrows.remove() # Raises NotImplementedError
下图说明了该示例。
左:流图,右:剩余箭头。
对于上下文,我试图将流线添加到现有的 imshow 动画(使用matplotlib.animation.FuncAnimation https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.animation.FuncAnimation.html)。
在此设置中,每帧仅更新图像数据,我无法清除并重新绘制完整的绘图。