如何以编程方式设置SpanSelector小部件的最小值和最大值

2024-04-29 16:53:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我想根据一个SpanSelector更新子地块,该选择器按预期工作。但另一个要求是,我需要将所选范围初始化为某些给定值。我试图调用_press_release函数,但它们只返回False,什么也没发生。如何以编程方式设置跨距,使选定跨距在跨距选择器中也可见

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))

Tags: 函数fromimporteventfalserelease编程方式
1条回答
网友
1楼 · 发布于 2024-04-29 16:53:31

设置选择矩形stay_rect,并使用初始xminxmax值调用onselect处理程序

示例:docs中示例的初始视图,在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)

enter image description here

相关问题 更多 >