如何设置按钮以删除由 MatPlotLib 中的另一个按钮创建的线

时间:2021-07-02 14:28:12

标签: python matplotlib

我正在尝试创建一个程序,该程序在按下按钮时绘制一条线,但在按下另一个按钮时删除该线。我遇到了麻烦,因为当我尝试按下删除按钮时,命令提示符出现错误,指出无法识别创建的行。任何帮助将不胜感激。

ax2_button = plt.axes([0.05, 0.7, 0.08, 0.05])
original_button = Button(ax2_button, 'Display', color='white', hovercolor='grey')

ax3_button = plt.axes([0.05, 0.6, 0.08, 0.05])
undo_button = Button(ax3_button, 'Remove', color='white', hovercolor='grey')

def plot(event):
    original,=ax.plot(X, Y, 'g-')

def plotundo(event):
    original.remove()

#Prints S/N data in command prompt when pressed#
SN_button.on_clicked(SN)
original_button.on_clicked(plot)
undo_button.on_clicked(plotundo)

plt.show()

0 个答案:

没有答案