[英]Turn off the Spanselector in matplotlib
I am trying to turn off the spanselector after using it. 我正在尝试使用spanselector后将其关闭。 When i go to the matplotlib documents, it says about this: 当我转到matplotlib文档时,它说的是:
Set the visible attribute to False if you want to turn off the functionality of the span selector
But I do not know how to turn off the functionality of span selector like the documentation states. 但是我不知道如何像文档说明一样关闭跨度选择器的功能。
Here is the code that I have. 这是我的代码。
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
In order to toggle the visibility of the SpanSelector
you will need to use the set_visible()
method. 为了切换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)
Here I have created it right after object creation, but you can call the set_visible()
from anywhere to disable the selector as long you have the SpanSelector
object. 在这里,我是在创建对象后立即创建它的,但是只要有SpanSelector
对象,就可以从任何地方调用set_visible()
以禁用选择器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.