def on_enter(event):
    axcut.set_visible(True)

def on_leave(event):
    axcut.set_visible(False)

def _yes(event):
    print('yolo')
mean = np.mean(dataY)
standardDeviation = np.std(dataY)
ax.plot(dataX, dataY, linewidth=0.5)
plt.connect('button_press_event', on_click)
plt.connect('axes_enter_event', on_enter)
plt.connect('axes_leave_event', on_leave)
axcut = plt.axes([0.9, 0.0, 0.1, 0.075])
bcut = Button(axcut, 'YES', color='red', hovercolor='green')
axcut.set_visible(False)
bcut.on_clicked(_yes)
plt.show()
How can I hide a custom button when saving a matplotlib figure?