我试图在使用后关闭spanselector。当我转到matplotlib文档时,它会说:
Set the visible attribute to False if you want to turn off the functionality of the span selector
但我不知道如何关闭span选择器的功能,如文档状态。
这是我的代码。
def disconnect_span(self):
if self.selection_mode == None: #This is a variable that i use to call this method
self.SpanSelector(self.axes, self.onselect, "horizontal", useblit = True,
rectprops = dict(alpha= 0.5, facecolor = "blue"))
self.figure_canvas.draw_idle()
else:
#Here is where i want to put the disconnect condition
答案 0 :(得分:2)
要切换SpanSelector
的展示率,您需要使用set_visible()
方法。
import matplotlib.pyplot as plt
from matplotlib.widgets import SpanSelector
ax = plt.subplot(111)
ax.plot([1,2], [3,4])
def onselect(vmin, vmax):
print vmin, vmax
span = SpanSelector(ax, onselect, 'horizontal')
span.set_visible(False)
我在创建对象后立即创建了它,但只要您拥有set_visible()
对象,就可以从任何地方调用SpanSelector
来禁用选择器。