使用按钮时无法删除艺术家

时间:2018-06-26 08:45:28

标签: python-2.7 matplotlib matplotlib-widget

我试图弄清楚如何在图形上添加和删除artist

这是我目前拥有的:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Button
import matplotlib.image as mpimg
from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, AnnotationBbox

fig, ax = plt.subplots()

ax.set_xlim(-5, 5)
ax.set_ylim(-50, 90)

arr_camera = mpimg.imread('Camera.png')
imagebox = OffsetImage(arr_camera, zoom=0.5)

class Index(object):
    def __init__(self, line):
        self.line = line
        self._remove_method = None

    def set_remove_method(self, f):
        self._remove_method = f

    def test(self, event):
        if self.line.get_visible():
            self.line.remove()
        else:
            self.line.set_image('Camera.png')
            self.line.axes.relim()
        self.line.ax.add_artist(ac)

line = AnnotationBbox(imagebox, (0, 0))

callback = Index(line)
axtest = plt.axes([0.81, 0.05, 0.1, 0.075])
btest = Button(axtest, 'Test')
btest.on_clicked(callback.test)


plt.show()

我仍然收到以下消息:

NotImplementedError: cannot remove artist

我不明白为什么会出现此消息,因为我使用了_remove_method()函数。

有人可以帮我吗?

0 个答案:

没有答案