关闭 matplotlib 中的 Spanselector
Turn off the Spanselector in matplotlib
我想在使用后关闭 spanselector。当我查看 matplotlib 文档时,它是这样说的:
Set the visible attribute to False if you want to turn off the functionality of the span selector
但我不知道如何像文档所述那样关闭跨度选择器的功能。
这是我的代码。
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
为了切换 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)
我在创建对象后立即创建了它,但是只要您有 SpanSelector
对象,您就可以从任何地方调用 set_visible()
来禁用选择器。
我想在使用后关闭 spanselector。当我查看 matplotlib 文档时,它是这样说的:
Set the visible attribute to False if you want to turn off the functionality of the span selector
但我不知道如何像文档所述那样关闭跨度选择器的功能。
这是我的代码。
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
为了切换 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)
我在创建对象后立即创建了它,但是只要您有 SpanSelector
对象,您就可以从任何地方调用 set_visible()
来禁用选择器。