好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > matplotlib之多邊形選區(PolygonSelector)的使用

matplotlib之多邊形選區(PolygonSelector)的使用

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

多邊形選區概述

多邊形選區是一種常見的對象選擇方式,在一個子圖中,單擊鼠標左鍵即構建一個多邊形的端點,最后一個端點與第一個端點重合即完成多邊形選區,選區即為多個端點構成的多邊形。在matplotlib中的多邊形選區屬于部件(widgets),matplotlib中的部件都是中性(neutral )的,即與具體后端實現無關。

多邊形選區具體實現定義為matplotlib.widgets.PolygonSelector類,繼承關系為:Widget->AxesWidget->_SelectorWidget->PolygonSelector。

PolygonSelector類的簽名為class matplotlib.widgets.PolygonSelector(ax, onselect, useblit=False, lineprops=None, markerprops=None, vertex_select_radius=15)

PolygonSelector類構造函數的參數為:

  • ax:多邊形選區生效的子圖,類型為matplotlib.axes.Axes的實例。
  • onselect:多邊形選區完成后執行的回調函數,函數簽名為def onselect( vertices),vertices數據類型為列表,列表元素格式為(xdata,ydata)元組。
  • drawtype:多邊形選區的外觀,取值范圍為{"box", "line", "none"},"box"為多邊形框,"line"為多邊形選區對角線,"none"無外觀,類型為字符串,默認值為"box"。
  • lineprops:多邊形選區線條的屬性,默認值為dict(color='k', linestyle='-', linewidth=2, alpha=0.5)。
  • markerprops:多邊形選區端點的屬性,默認值為dict(marker='o', markersize=7, mec='k', mfc='k', alpha=0.5)。
  • vertex_select_radius:多邊形端點的選擇半徑,浮點數,默認值為15,用于端點選擇或者多邊形閉合。

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

  • “move_all”: 移動已存在的選區,默認為"shift"。
  • “clear”:清除現有選區,默認為 "escape",即esc鍵。
  • “move_vertex”:正方形選區,默認為"control"。

PolygonSelector類中的verts特性返回多邊形選區中的多有端點,類型為列表,元素為(x,y)元組,即端點的坐標元組。

案例

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

案例說明

單擊鼠標左鍵創建端點,最終點擊初始端點閉合多邊形,形成多邊形選區。選區外的數據元素顏色變淡,選區內數據顏色保持不變。

按esc鍵取消選區。按shift鍵鼠標可以移動多邊形選區位置,按ctrl鍵鼠標可以移動多邊形選區某個端點的位置。退出程序時,控制臺輸出選區內數據元素的坐標。

控制臺輸出:

Selected points:
[[2.0 2.0]
 [1.0 3.0]
 [2.0 3.0]]

案例代碼

import numpy as np

from matplotlib.widgets import PolygonSelector
from matplotlib.path import Path


class SelectFromCollection:
  """
  Select indices from a matplotlib collection using `PolygonSelector`.

  Selected indices are saved in the `ind` attribute. This tool fades out the
  points that are not part of the selection (i.e., reduces their alpha
  values). If your collection has alpha  1, this tool will permanently
  alter the alpha values.

  Note that this tool selects collection objects based on their *origins*
  (i.e., `offsets`).

  Parameters
  ----------
  ax : `~matplotlib.axes.Axes`
    Axes to interact with.
  collection : `matplotlib.collections.Collection` subclass
    Collection you want to select from.
  alpha_other : 0 = float = 1
    To highlight a selection, this tool sets all selected points to an
    alpha value of 1 and non-selected points to *alpha_other*.
  """

  def __init__(self, ax, collection, alpha_other=0.3):
    self.canvas = ax.figure.canvas
    self.collection = collection
    self.alpha_other = alpha_other

    self.xys = collection.get_offsets()
    self.Npts = len(self.xys)

    # Ensure that we have separate colors for each object
    self.fc = collection.get_facecolors()
    if len(self.fc) == 0:
      raise ValueError('Collection must have a facecolor')
    elif len(self.fc) == 1:
      self.fc = np.tile(self.fc, (self.Npts, 1))

    self.poly = PolygonSelector(ax, self.onselect)
    self.ind = []

  def onselect(self, verts):
    path = Path(verts)
    self.ind = np.nonzero(path.contains_points(self.xys))[0]
    self.fc[:, -1] = self.alpha_other
    self.fc[self.ind, -1] = 1
    self.collection.set_facecolors(self.fc)
    self.canvas.draw_idle()

  def disconnect(self):
    self.poly.disconnect_events()
    self.fc[:, -1] = 1
    self.collection.set_facecolors(self.fc)
    self.canvas.draw_idle()


if __name__ == '__main__':
  import matplotlib.pyplot as plt

  fig, ax = plt.subplots()
  grid_size = 5
  grid_x = np.tile(np.arange(grid_size), grid_size)
  grid_y = np.repeat(np.arange(grid_size), grid_size)
  pts = ax.scatter(grid_x, grid_y)

  selector = SelectFromCollection(ax, pts)

  print("Select points in the figure by enclosing them within a polygon.")
  print("Press the 'esc' key to start a new polygon.")
  print("Try holding the 'shift' key to move all of the vertices.")
  print("Try holding the 'ctrl' key to move a single vertex.")

  plt.show()

  selector.disconnect()

  # After figure is closed print the coordinates of the selected points
  print('\nSelected points:')
  print(selector.xys[selector.ind])

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

您可能感興趣的文章:
  • 詳解Golang并發操作中常見的死鎖情形
  • Go 語言中的死鎖問題解決
  • Go語言死鎖與goroutine泄露問題的解決
  • golang coroutine 的等待與死鎖用法
  • go select編譯期的優化處理邏輯使用場景分析
  • Django實現jquery select2帶搜索的下拉框
  • Go語言使用select{}阻塞main函數介紹
  • golang中的select關鍵字用法總結
  • Go select 死鎖的一個細節

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

巨人網絡通訊聲明:本文標題《matplotlib之多邊形選區(PolygonSelector)的使用》,本文關鍵詞  matplotlib,之,多邊形,選區,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《matplotlib之多邊形選區(PolygonSelector)的使用》相關的同類信息!
  • 本頁收集關于matplotlib之多邊形選區(PolygonSelector)的使用的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 芒果app管鲍之富二代app| 全彩ACG??无翼乌邪恶游泳| 一本大道AV伊人久久综合蜜芽 | 嗯~~~啊漫画| 进一点再进一点好爽视频| 久久久青青| 999yy成年在线视频免费看| 女人被公牛进入| 老婆从拒绝到接受3q的含义| 被夫上司连续被7天侵犯在线观看| 骚骚网站| 亚洲精品福利视频| jizz女人水多| 岳两条雪白大| 广西女人一级毛片| 社会| 131美女做爰看片| 国产乱人伦AV麻豆网| 国产伦精品一区二区三区网站| 性生交大片免费全播放| chinese一区福利在线| 艹逼视频免费看| 肉感巨凥AV视频社区在线| 免费黄色软件在线下载| 被?到爽禁????免费视频| 免费?无码?日本真人网页版| 成人毛片18女人毛片免费96| 耸动的粉嫩小屁股| 人妻亂伦中文字幕| 国产国语一级毛片| 黄色 s色| 俄罗斯老妇性欧美毛茸茸孕交| 夫の目の前侵犯入侵者中文字幕| 亚洲欧美另类视频| 亚洲国产日韩a在线欧美2020| 长腿嫩模打开双腿呻吟| 菲律宾伦理片| 猫咪成人最新地域网名怎么取| 蜜臀久久99精品久久久久久| 亚洲一级A片毛毛aA片18| 酒色成人网|