婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > matplotlib 范圍選區(SpanSelector)的使用

matplotlib 范圍選區(SpanSelector)的使用

熱門標簽:400電話辦理費用收費 高德地圖標注字母 千呼ai電話機器人免費 申請辦個400電話號碼 騰訊地圖標注有什么版本 柳州正規電銷機器人收費 鎮江人工外呼系統供應商 外呼系統前面有錄音播放嗎 深圳網絡外呼系統代理商

范圍選區概述

范圍選區是一種常見的對象選擇方式,在一個子圖中,可以在某一個軸方向上用鼠標選擇起始范圍的數據,這個特性可用來實現數據縮放(datazoom)。在matplotlib中的范圍選區屬于部件(widgets),matplotlib中的部件都是中性(neutral )的,即與具體后端實現無關。

范圍選區具體實現定義為matplotlib.widgets.SpanSelector類,繼承關系為:Widget->AxesWidget->_SelectorWidget->SpanSelector

SpanSelector類的簽名為class matplotlib.widgets.SpanSelector(ax, onselect, direction, minspan=None, useblit=False, rectprops=None, onmove_callback=None, span_stays=False, button=None)

SpanSelector類構造函數的參數為:

  • ax:范圍選區生效的子圖,類型為matplotlib.axes.Axes的實例。
  • onselect:范圍選區完成后執行的回調函數,函數簽名為def func(min, max)minmax的數據類型均為浮點數,表示選區在某個坐標軸方向上的最小值和最大值。
  • direction:范圍選區的坐標軸方向,取值范圍為{"horizontal", "vertical"},類型為字符串。
  • minspan:選區的最小范圍,選區范圍小于minspan將不會觸發onselectrectprops:范圍選區的外觀的屬性,默認值為None
  • span_stays:布爾值,是否在鼠標釋放后仍然保留選區,默認值為False
  • onmove_callback:當選區確定后移動鼠標觸發的回調函數,函數簽名為def func(min, max)minmax的數據類型均為浮點數,默認值為None

SpanSelector類中的state_modifier_keys公有變量 state_modifier_keys定義了操作快捷鍵,類型為字典。

案例:范圍選取基本實現

官方案例一,范圍選區基本實現。

案例說明


單擊鼠標拖動到適當位置釋放鼠標形成范圍選區,選區為透明度0.5藍色,控制臺輸出選區在橫坐標軸上的最大、最小坐標。
控制臺輸出:

1.569758064516129 2.0044354838709677

案例代碼

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)
rectprops = dict(facecolor='blue', alpha=0.5)
span = mwidgets.SpanSelector(ax, onselect, 'horizontal',span_stays=True,
               rectprops=rectprops)
plt.show()

案例:數據縮放功能

官方案例,https://matplotlib.org/gallery/widgets/span_selector.html

案例說明


在上方子圖單擊鼠標拖動到適當位置釋放鼠標形成范圍選區,選區為紅色,下方子圖重繪為選定區域內數據系列,起到了數據放大的效果。

案例代碼

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import SpanSelector

# Fixing random state for reproducibility
np.random.seed(19680801)

fig, (ax1, ax2) = plt.subplots(2, figsize=(8, 6))
ax1.set(facecolor='#FFFFCC')

x = np.arange(0.0, 5.0, 0.01)
y = np.sin(2*np.pi*x) + 0.5*np.random.randn(len(x))

ax1.plot(x, y, '-')
ax1.set_ylim(-2, 2)
ax1.set_title('Press left mouse button and drag to test')

ax2.set(facecolor='#FFFFCC')
line2, = ax2.plot(x, y, '-')


def onselect(xmin, xmax):
  indmin, indmax = np.searchsorted(x, (xmin, xmax))
  indmax = min(len(x) - 1, indmax)

  thisx = x[indmin:indmax]
  thisy = y[indmin:indmax]
  line2.set_data(thisx, thisy)
  ax2.set_xlim(thisx[0], thisx[-1])
  ax2.set_ylim(thisy.min(), thisy.max())
  fig.canvas.draw()
  
span = SpanSelector(ax1, onselect, 'horizontal', useblit=True, span_stays=True,
          rectprops=dict(alpha=0.5, facecolor='red'))
# Set useblit=True on most backends for enhanced performance.

plt.show()

到此這篇關于matplotlib 范圍選區(SpanSelector)的使用的文章就介紹到這了,更多相關matplotlib 范圍選區內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Python matplotlib學習筆記之坐標軸范圍
  • Python設置matplotlib.plot的坐標軸刻度間隔以及刻度范圍

標簽:海南 平頂山 合肥 烏蘭察布 大慶 郴州 烏蘭察布 哈爾濱

巨人網絡通訊聲明:本文標題《matplotlib 范圍選區(SpanSelector)的使用》,本文關鍵詞  matplotlib,范圍,選區,SpanSelector,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《matplotlib 范圍選區(SpanSelector)的使用》相關的同類信息!
  • 本頁收集關于matplotlib 范圍選區(SpanSelector)的使用的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 化德县| 青川县| 武陟县| 吉木乃县| 海安县| 越西县| 高雄市| 达州市| 曲阜市| 浮梁县| 青龙| 凤阳县| 陆河县| 广灵县| 万山特区| 平果县| 阿克陶县| 武穴市| 藁城市| 惠水县| 保康县| 精河县| 清镇市| 金乡县| 纳雍县| 于田县| 嫩江县| 黑河市| 榆中县| 蒙自县| 准格尔旗| 五常市| 灌阳县| 池州市| 汉源县| 呼图壁县| 栖霞市| 东阳市| 临朐县| 岢岚县| 介休市|