最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

matplotlib繪制多子圖共享鼠標(biāo)光標(biāo)的方法示例

 更新時間:2021年01月08日 11:48:54   作者:mighty13  
這篇文章主要介紹了matplotlib繪制多子圖共享鼠標(biāo)光標(biāo)的方法示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

matplotlib官方除了提供了鼠標(biāo)十字光標(biāo)的示例,還提供了同一圖像內(nèi)多子圖共享光標(biāo)的示例,其功能主要由widgets模塊中的MultiCursor類提供支持。

MultiCursor類與Cursor類參數(shù)類似,差異主要在:

  • Cursor類參數(shù)只有一個ax,即需要顯示光標(biāo)的子圖;MultiCursor類參數(shù)為canvasaxes,其中axes為需要共享光標(biāo)的子圖列表。
  • Cursor類中,光標(biāo)默認(rèn)是十字線;MultiCursor類中,光標(biāo)默認(rèn)為豎線。

官方示例

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

t = np.arange(0.0, 2.0, 0.01)
s1 = np.sin(2*np.pi*t)
s2 = np.sin(4*np.pi*t)

fig, (ax1, ax2) = plt.subplots(2, sharex=True)
ax1.plot(t, s1)
ax2.plot(t, s2)

multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1)
plt.show()

在這里插入圖片描述

簡易修改版

multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1, horizOn=True, vertOn=True)

在這里插入圖片描述

MultiCursor類源碼

class MultiCursor(Widget):
  """
  Provide a vertical (default) and/or horizontal line cursor shared between
  multiple axes.

  For the cursor to remain responsive you must keep a reference to it.

  Example usage::

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

    fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True)
    t = np.arange(0.0, 2.0, 0.01)
    ax1.plot(t, np.sin(2*np.pi*t))
    ax2.plot(t, np.sin(4*np.pi*t))

    multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1,
              horizOn=False, vertOn=True)
    plt.show()

  """
  def __init__(self, canvas, axes, useblit=True, horizOn=False, vertOn=True,
         **lineprops):

    self.canvas = canvas
    self.axes = axes
    self.horizOn = horizOn
    self.vertOn = vertOn

    xmin, xmax = axes[-1].get_xlim()
    ymin, ymax = axes[-1].get_ylim()
    xmid = 0.5 * (xmin + xmax)
    ymid = 0.5 * (ymin + ymax)

    self.visible = True
    self.useblit = useblit and self.canvas.supports_blit
    self.background = None
    self.needclear = False

    if self.useblit:
      lineprops['animated'] = True

    if vertOn:
      self.vlines = [ax.axvline(xmid, visible=False, **lineprops)
              for ax in axes]
    else:
      self.vlines = []

    if horizOn:
      self.hlines = [ax.axhline(ymid, visible=False, **lineprops)
              for ax in axes]
    else:
      self.hlines = []

    self.connect()
    
  def connect(self):
    """Connect events."""
    self._cidmotion = self.canvas.mpl_connect('motion_notify_event',
                         self.onmove)
    self._ciddraw = self.canvas.mpl_connect('draw_event', self.clear)

  def disconnect(self):
    """Disconnect events."""
    self.canvas.mpl_disconnect(self._cidmotion)
    self.canvas.mpl_disconnect(self._ciddraw)

  def clear(self, event):
    """Clear the cursor."""
    if self.ignore(event):
      return
    if self.useblit:
      self.background = (
        self.canvas.copy_from_bbox(self.canvas.figure.bbox))
    for line in self.vlines + self.hlines:
      line.set_visible(False)

  def onmove(self, event):
    if self.ignore(event):
      return
    if event.inaxes is None:
      return
    if not self.canvas.widgetlock.available(self):
      return
    self.needclear = True
    if not self.visible:
      return
    if self.vertOn:
      for line in self.vlines:
        line.set_xdata((event.xdata, event.xdata))
        line.set_visible(self.visible)
    if self.horizOn:
      for line in self.hlines:
        line.set_ydata((event.ydata, event.ydata))
        line.set_visible(self.visible)
    self._update()


  def _update(self):
    if self.useblit:
      if self.background is not None:
        self.canvas.restore_region(self.background)
      if self.vertOn:
        for ax, line in zip(self.axes, self.vlines):
          ax.draw_artist(line)
      if self.horizOn:
        for ax, line in zip(self.axes, self.hlines):
          ax.draw_artist(line)
      self.canvas.blit()
    else:
      self.canvas.draw_idle()

到此這篇關(guān)于matplotlib繪制多子圖共享鼠標(biāo)光標(biāo)的方法示例的文章就介紹到這了,更多相關(guān)matplotlib 多子圖鼠標(biāo)光標(biāo)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 使用python實(shí)現(xiàn)將視頻中的音頻分離出來

    使用python實(shí)現(xiàn)將視頻中的音頻分離出來

    這篇文章主要介紹了使用python實(shí)現(xiàn)將視頻中的音頻分離出來,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • Pytorch根據(jù)layers的name凍結(jié)訓(xùn)練方式

    Pytorch根據(jù)layers的name凍結(jié)訓(xùn)練方式

    今天小編就為大家分享一篇Pytorch根據(jù)layers的name凍結(jié)訓(xùn)練方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • 淺談Python type的使用

    淺談Python type的使用

    今天小編就為大家分享一篇淺談Python type的使用,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • Django模型序列化返回自然主鍵值示例代碼

    Django模型序列化返回自然主鍵值示例代碼

    這篇文章主要給大家介紹了關(guān)于Django模型序列化返回自然主鍵值的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Django具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • python?通過dict(zip)和{}的方式構(gòu)造字典的方法

    python?通過dict(zip)和{}的方式構(gòu)造字典的方法

    在python中,通常通過dict和zip組合來構(gòu)建鍵值對,這篇文章主要介紹了python?通過dict(zip)和{}的方式構(gòu)造字典的方法,需要的朋友可以參考下
    2022-07-07
  • Django集成百度富文本編輯器uEditor攻略

    Django集成百度富文本編輯器uEditor攻略

    UEditor是由百度web前端研發(fā)部開發(fā)所見即所得富文本web編輯器,具有輕量,可定制,注重用戶體驗(yàn)等特點(diǎn),開源基于MIT協(xié)議,允許自由使用和修改代碼。
    2014-07-07
  • Python實(shí)現(xiàn)簡單的語音識別系統(tǒng)

    Python實(shí)現(xiàn)簡單的語音識別系統(tǒng)

    這篇文章主要介紹了Python實(shí)現(xiàn)簡單的語音識別系統(tǒng),具有一定借鑒價值,需要的朋友可以參考下。
    2017-12-12
  • 老生常談Python中的Pickle庫

    老生常談Python中的Pickle庫

    pickle是python語言的一個標(biāo)準(zhǔn)模塊,安裝python后已包含pickle庫,不需要單獨(dú)再安裝。這篇文章主要介紹了Python中的Pickle庫,需要的朋友可以參考下
    2022-01-01
  • Python將視頻轉(zhuǎn)換為圖片介紹

    Python將視頻轉(zhuǎn)換為圖片介紹

    大家好,本篇文章主要講的是Python將視頻轉(zhuǎn)換為圖片介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2022-01-01
  • Flask框架中的session設(shè)置詳解

    Flask框架中的session設(shè)置詳解

    Flask是一個使用Python編寫的輕量級Web應(yīng)用框架。其WSGI工具箱采用Werkzeug,模板引擎則使用 Jinja2 。Flask使用BSD授權(quán)。Flask也被稱為 “microframework”,因?yàn)樗褂煤唵蔚暮诵模胑xtension增加其他功能
    2023-02-02

最新評論

太白县| 察哈| 菏泽市| 阿勒泰市| 东台市| 神池县| 齐河县| 台南市| 吉安市| 天津市| 郧西县| 房产| 民权县| 潍坊市| 永善县| 临海市| 揭东县| 苗栗县| 隆林| 唐河县| 东兴市| 莒南县| 固安县| 克拉玛依市| 汤阴县| 琼海市| 英德市| 浮山县| 广丰县| 交口县| 沧源| 平泉县| 庆阳市| 无棣县| 乌什县| 鹿邑县| 从化市| 武安市| 保定市| 当阳市| 镇原县|