我想根据可以正常工作的SpanSelector更新子图。但是另一个要求是,我需要将所选范围初始化为一些给定值。我曾试着拨打_press
,_release
功能,但它们只是返回False
,并没有任何反应。如何以编程方式设置跨度,以使所选跨度在SpanSelector中也可见?
from matplotlib.widgets import SpanSelector
from collections import namedtuple
widgets.append(
SpanSelector(range_ax, onselect=self._plot_subplots, direction='horizontal', rectprops=dict(alpha=0.5, facecolor='red'), span_stays=True)
)
# fake some events
Event = namedtuple('Event', ['xdata', 'ydata'])
widgets[0]._press(Event(0, 119))
widgets[0]._release(Event(500, 120))
设置选择矩形stay_rect
并onselect
使用初始值xmin
和xmax
值调用处理程序。
示例:文档中示例的初始视图,并在其之前插入了以下内容plt.show()
:
xmin, xmax = 3, 4
span.stay_rect.set_bounds(xmin, 0, xmax-xmin, 1)
span.stay_rect.set_visible(True)
span.onselect(xmin, xmax)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句