本文簡要介紹 python 語言中 matplotlib.widgets.SpanSelector
的用法。
-
基礎:
_SelectorWidget
在單個軸上直觀地選擇最小/最大範圍並使用這些值調用函數。
為保證選擇器保持響應,請保留對它的引用。
為了關閉 SpanSelector,請將
span_selector.active
設置為 False。要重新打開它,請將其設置為 True。在選擇之外的相同坐標處觸發的按下和釋放事件將清除選擇器,但
ignore_event_outside=True
除外。- 參數:
- ax
Axes
- onselect 可使用簽名
func(min: float, max: float)
調用 -
在釋放事件和創建、更改或刪除選擇後調用的回調函數。
- direction {"horizontal","vertical"}
-
繪製跨度選擇器的方向。
- minspan 浮點數,默認值:0
-
如果選擇小於或等於
minspan
,則選擇被刪除(當已經存在時)或取消。 - useblit 布爾值,默認值:假
-
如果為 True,則使用 backend-dependent blitting 函數以加快畫布更新速度。有關詳細信息,請參閱教程使用位圖傳輸加快渲染速度。
- props 字典,默認:{'facecolor':'red', 'alpha':0.5}
-
Patch
屬性的字典。 - onmove_callback 可使用簽名
func(min: float, max: float)
調用,可選 -
在選擇跨度時在鼠標移動時調用。
- interactive 布爾值,默認值:假
-
是否繪製一組允許在繪製後與小部件交互的句柄。
- button
MouseButton
或MouseButton
列表,默認值:所有按鈕 -
激活跨度選擇器的鼠標按鈕。
- handle_props 字典,默認值:無
-
跨度邊的手柄線的屬性。僅在
interactive
為 True 時使用。有關有效屬性,請參閱Line2D
。 - grab_range 浮點數,默認值:10
-
可以激活交互式工具手柄的距離(以像素為單位)。
- state_modifier_keys 字典,可選
-
影響小部件行為的鍵盤修飾符。值修改了默認值,它們是:
-
"clear":清除當前形狀,默認:"escape"。
-
- drag_from_anywhere 布爾值,默認值:假
-
如果
True
,則可以通過單擊其範圍內的任意位置來移動小部件。 - ignore_event_outside 布爾值,默認值:假
-
如果
True
,在跨度選擇器之外觸發的事件將被忽略。 - snap_values 一維數組,可選
-
將選擇器邊捕捉到給定值。
- ax
例子
>>> import matplotlib.pyplot as plt >>> import matplotlib.widgets as mwidgets >>> fig, ax = plt.subplots() >>> ax.plot([1, 2, 3], [10, 50, 100]) >>> def onselect(vmin, vmax): ... print(vmin, vmax) >>> span = mwidgets.SpanSelector(ax, onselect, 'horizontal', ... props=dict(facecolor='blue', alpha=0.5)) >>> fig.show()
另請參閱:跨度選擇器
用法
class matplotlib.widgets.SpanSelector(ax, onselect, direction, *, minspan=0, useblit=False, props=None, onmove_callback=None, interactive=False, button=None, handle_props=None, grab_range=10, state_modifier_keys=None, drag_from_anywhere=False, ignore_event_outside=False, snap_values=None)
相關用法
- Python matplotlib Spines用法及代碼示例
- Python matplotlib StarPolygonCollection.set_hatch用法及代碼示例
- Python matplotlib SubFigure.subplots用法及代碼示例
- Python matplotlib SubplotSpec.subgridspec用法及代碼示例
- Python matplotlib SubFigure.add_axes用法及代碼示例
- Python matplotlib SubFigure.colorbar用法及代碼示例
- Python matplotlib Sankey用法及代碼示例
- Python matplotlib SubFigure.sticky_edges用法及代碼示例
- Python matplotlib Substitution用法及代碼示例
- Python matplotlib SubFigure用法及代碼示例
- Python matplotlib SubFigure.add_gridspec用法及代碼示例
- Python matplotlib SubFigure.add_subplot用法及代碼示例
- Python matplotlib SubFigure.align_xlabels用法及代碼示例
- Python matplotlib SubFigure.align_ylabels用法及代碼示例
- Python matplotlib StarPolygonCollection.sticky_edges用法及代碼示例
- Python matplotlib SubFigure.legend用法及代碼示例
- Python matplotlib StarPolygonCollection用法及代碼示例
- Python matplotlib axvspan用法及代碼示例
- Python matplotlib Axes.get_legend_handles_labels用法及代碼示例
- Python matplotlib AbstractMovieWriter用法及代碼示例
- Python matplotlib triplot用法及代碼示例
- Python matplotlib Axes.hist用法及代碼示例
- Python matplotlib boxplot用法及代碼示例
- Python matplotlib subplots用法及代碼示例
- Python matplotlib InsetPosition用法及代碼示例
注:本文由純淨天空篩選整理自skytowner.com大神的英文原創作品 matplotlib.widgets.SpanSelector。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。