校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > matplotlib交互式數據光標mpldatacursor的實現

matplotlib交互式數據光標mpldatacursor的實現

熱門標簽:滴滴地圖標注公司 江門智能電話機器人 智能電話機器人調研 地圖標注可以遠程操作嗎 天津塘沽區地圖標注 400電話在線如何申請 甘肅高頻外呼系統 杭州房產地圖標注 如何申請400電話代理

簡介

mpldatacursor包可以為matplotlib提供交互式的數據光標(彈出式注釋框)。
它的典型功能是:

  • 鼠標左鍵單擊圖表數據元素時會彈出文本框顯示最近的數據元素的坐標值。
  • 鼠標右鍵單擊文本框取消顯示數據光標。
  • d鍵時切換顯示\關閉數據光標。

 

安裝

如果matplotlib版本低于3.3可以直接使用pip安裝

pip install mpldatacursor

如果matplotlib版本高于3.3,雖然pip安裝成功,但是運行案例時會出現AttributeError: 'ScalarFormatter' object has no attribute 'pprint_val'錯誤。

通過查看源碼可知:

try:
  # Again, older versions of mpl
  return formatter.pprint_val(x)
except AttributeError:
  # 3.3.0 or later
  return formatter.format_data_short(x)

通過分析,預計是因為使用了國內pip源,mpldatacursor包還未修復該問題(pip 安裝的 mpldatacursor包版本號是0.7.1)。

因此,建議到https://github.com/joferkington/mpldatacursor

下載源碼,進行源碼安裝(源碼安裝的 mpldatacursor包版本號是0.7.dev0)。

python setup.py install

基本應用(官方實例)解析

應用流程

mpldatacursor包基本應用方式比較簡單:

  • mpldatacursor包中導入datacursor函數。
  • 應用datacursor函數。

 包結構

查看源碼可知,mpldatacursor包的結構如下:

mpldatacursor
   convenience.py
   datacursor.py
   pick_info.py
   __init__.py

datacursor函數定義在convenience.py中,datacursor函數的返回值是DataCursor類實例。
DataCursor類定義在datacursor.py中。
pick_info.py定義了一系列和彈出文本框相關的函數,供DataCursor類調用。

datacursor函數定義

datacursor函數定義可知:

  • datacursor函數可以不提供參數,這樣圖像內所有數據元素都會應用交互式數據光標。
  • datacursor函數可以指定哪些數據元素應用交互式數據光標。
def datacursor(artists=None, axes=None, **kwargs):
  """
  Create an interactive data cursor for the specified artists or specified
  axes. The data cursor displays information about a selected artist in a
  "popup" annotation box.

  If a specific sequence of artists is given, only the specified artists will
  be interactively selectable. Otherwise, all manually-plotted artists in
  *axes* will be used (*axes* defaults to all axes in all figures).

  Parameters
  -----------
  artists : a matplotlib artist or sequence of artists, optional
    The artists to make selectable and display information for. If this is
    not specified, then all manually plotted artists in `axes` will be
    used.
  axes : a matplotlib axes of sequence of axes, optional
    The axes to selected artists from if a sequence of artists is not
    specified. If `axes` is not specified, then all available axes in all
    figures will be used.
  tolerance : number, optional
    The radius (in points) that the mouse click must be within to select
    the artist. Default: 5 points.
  formatter : callable, optional
    A function that accepts arbitrary kwargs and returns a string that will
    be displayed with annotate. Often, it is convienent to pass in the
    format method of a template string, e.g.
    ``formatter="{label}".format``.
    Keyword arguments passed in to the `formatter` function:
      `x`, `y` : floats
        The x and y data coordinates of the clicked point
      `event` : a matplotlib ``PickEvent``
        The pick event that was fired (note that the selected
        artist can be accessed through ``event.artist``).
      `label` : string or None
        The legend label of the selected artist.
      `ind` : list of ints or None
        If the artist has "subitems" (e.g. points in a scatter or
        line plot), this will be a list of the item(s) that were
        clicked on. If the artist does not have "subitems", this
        will be None. Note that this is always a list, even when
        a single item is selected.
    Some selected artists may supply additional keyword arguments that
    are not always present, for example:
      `z` : number
        The "z" (usually color or array) value, if present. For an
        ``AxesImage`` (as created by ``imshow``), this will be the
        uninterpolated array value at the point clicked. For a
        ``PathCollection`` (as created by ``scatter``) this will be the
        "c" value if an array was passed to "c".
      `i`, `j` : ints
        The row, column indicies of the selected point for an
        ``AxesImage`` (as created by ``imshow``)
      `s` : number
        The size of the selected item in a ``PathCollection`` if a size
        array is specified.
      `c` : number
        The array value displayed as color for a ``PathCollection``
        if a "c" array is specified (identical to "z").
      `point_label` : list
        If `point_labels` is given when the data cursor is initialized
        and the artist has "subitems", this will be a list of the items
        of `point_labels` that correspond to the selected artists.
        Note that this is always a list, even when a single artist is
        selected.
      `width`, `height`, `top`, `bottom` : numbers
        The parameters for ``Rectangle`` artists (e.g. bar plots).
  point_labels : sequence or dict, optional
    For artists with "subitems" (e.g. Line2D's), the item(s) of
    `point_labels` corresponding to the selected "subitems" of the artist
    will be passed into the formatter function as the "point_label" kwarg.
    If a single sequence is given, it will be used for all artists with
    "subitems". Alternatively, a dict of artist:sequence pairs may be given
    to match an artist to the correct series of point labels.
  display : {"one-per-axes", "single", "multiple"}, optional
    Controls whether more than one annotation box will be shown.
    Default: "one-per-axes"
  draggable : boolean, optional
    Controls whether or not the annotation box will be interactively
    draggable to a new location after being displayed. Defaults to False.
  hover : boolean, optional
    If True, the datacursor will "pop up" when the mouse hovers over an
    artist. Defaults to False. Enabling hover also sets
    `display="single"` and `draggable=False`.
  props_override : function, optional
    If specified, this function customizes the parameters passed into the
    formatter function and the x, y location that the datacursor "pop up"
    "points" to. This is often useful to make the annotation "point" to a
    specific side or corner of an artist, regardless of the position
    clicked. The function is passed the same kwargs as the `formatter`
    function and is expected to return a dict with at least the keys "x"
    and "y" (and probably several others).
    Expected call signature: `props_dict = props_override(**kwargs)`
  keybindings : boolean or dict, optional
    By default, the keys "d" and "t" will be bound to deleting/hiding all
    annotation boxes and toggling interactivity for datacursors,
    respectively. If keybindings is False, the ability to hide/toggle
    datacursors interactively will be disabled. Alternatively, a dict of
    the form {'hide':'somekey', 'toggle':'somekey'} may specified to
    customize the keyboard shortcuts.
  date_format : string, optional
    The strftime-style formatting string for dates. Used only if the x or y
    axes have been set to display dates. Defaults to "%x %X".
  display_button: int, optional
    The mouse button that will triggers displaying an annotation box.
    Defaults to 1, for left-clicking. (Common options are 1:left-click,
    2:middle-click, 3:right-click)
  hide_button: int or None, optional
    The mouse button that triggers hiding the selected annotation box.
    Defaults to 3, for right-clicking. (Common options are 1:left-click,
    2:middle-click, 3:right-click, None:hiding disabled)
  keep_inside : boolean, optional
    Whether or not to adjust the x,y offset to keep the text box inside the
    figure. This option has no effect on draggable datacursors. Defaults to
    True. Note: Currently disabled on OSX and NbAgg/notebook backends.
  **kwargs : additional keyword arguments, optional
    Additional keyword arguments are passed on to annotate.

  Returns
  -------
  dc : A ``mpldatacursor.DataCursor`` instance
  """

官方實例源碼

import matplotlib.pyplot as plt
import numpy as np
from mpldatacursor import datacursor

data = np.outer(range(10), range(1, 5))

fig, ax = plt.subplots()
lines = ax.plot(data)
ax.set_title('Click somewhere on a line')

datacursor()

plt.show()

限定僅某數據元素使用交互式光標

本實例中,有兩個數據元素(artist):line1line2datacursor(line1)函數提供了參數line1,因此只有line1可以使用交互式數據光標,line2則沒有效果。

import matplotlib.pyplot as plt
import numpy as np
from mpldatacursor import datacursor
fig, ax = plt.subplots()
line1 = ax.plot([1,3])
line2 = ax.plot([1,2])
ax.set_title('Click somewhere on a line')
datacursor(line1)
plt.show()

其他官方實例功能概述

mpldatacursor提供了大量實際案例,詳見https://github.com/joferkington/mpldatacursor/tree/master/examples。不再一一分析,僅簡單說明功能。

  • basic_single_annotation.py:在多子圖情況下,默認每個子圖的數據光標是獨立的,即每個子圖都可以顯示數據光標,相互不影響。使用datacursor(display='single')參數后,僅在當前子圖顯示數據光標,其余子圖顯示的數據光標自動關閉。
  • change_popup_color.py:提供了兩個案例,一個取消了提示框的邊框,一個將提示框的背景色改為白色。
  • hover_example.py:將數據光標的觸發方式由鼠標左鍵單擊改為鼠標懸浮。
  • show_artist_labels.py:將數據光標默認顯示的坐標值改為數據元素的label
  • highlighting_example.py:點擊數據元素時,數據元素會高亮(黃色)顯示。
  • draggable_example.py:在一個子圖中,同時顯示多個數據光標。
  • customize_keyboard_shortcuts.py:重新綁定數據光標快捷鍵。
  • labeled_points_example.py:自定義數據點標簽。
  • date_example.py:日期數據顯示。
  • bar_example.py:在柱狀圖中,在每個柱上方鼠標懸浮觸發數據光標。

總結

mpldatacursor歷史悠久,但是遲遲沒有發布支持matplotlib3.3的穩定版,建議源碼安裝開發版,或者使用mplcursors包https://github.com/anntzer/mplcursors。
mpldatacursor功能上還是挺豐富的,可以作為深入學習matplotlib交互的案例。

到此這篇關于matplotlib交互式數據光標mpldatacursor的實現 的文章就介紹到這了,更多相關matplotlib交互式數據光標內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • matplotlib交互式數據光標實現(mplcursors)

標簽:長春 臨汾 東莞 德宏 漢中 河池 重慶 廊坊

巨人網絡通訊聲明:本文標題《matplotlib交互式數據光標mpldatacursor的實現》,本文關鍵詞  matplotlib,交互式,數據,光標,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《matplotlib交互式數據光標mpldatacursor的實現》相關的同類信息!
  • 本頁收集關于matplotlib交互式數據光標mpldatacursor的實現的相關信息資訊供網民參考!
  • 推薦文章
    校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃
    成人app软件下载大全免费| 国产精品免费视频网站| 亚洲一区二区三区中文字幕| 久久国产乱子精品免费女| 欧美色老头old∨ideo| 一区二区三区四区中文字幕| 国产成人精品免费| 国产欧美一区视频| 国产盗摄视频一区二区三区| 日韩精品中文字幕在线一区| 亚洲午夜精品久久久久久久久| 丁香天五香天堂综合| 国产视频在线观看一区二区三区| 韩国精品主播一区二区在线观看| 精品久久一区二区三区| 国产中文一区二区三区| 宅男噜噜噜66一区二区66| 日本少妇一区二区| 日韩视频免费直播| 极品美女销魂一区二区三区免费| 日韩欧美精品在线视频| 蜜臀国产一区二区三区在线播放| 欧美第一区第二区| 国产自产视频一区二区三区| 日韩欧美精品在线视频| 国产综合久久久久影院| 久久美女艺术照精彩视频福利播放 | 午夜精品久久久久影视| 欧美日韩国产美| 国产一区二区三区日韩| 26uuu亚洲| 国产成人精品免费网站| 一区二区三区久久| 精品福利在线导航| 99久久综合国产精品| 五月天激情综合| 久久精品一区二区| 欧美日韩国产精品自在自线| 国产一区二区调教| 亚洲综合偷拍欧美一区色| 精品日韩一区二区| 99re这里只有精品首页| 免费的国产精品| 中文字幕一区三区| 欧美一区二区私人影院日本| 国产成人精品亚洲777人妖| 一区二区三区高清| 久久网站最新地址| 欧美精品第一页| 成人天堂资源www在线| 男女视频一区二区| 亚洲男人的天堂一区二区| 精品福利av导航| 欧美丝袜丝交足nylons图片| 国产不卡免费视频| 久久精品国产一区二区三区免费看| 日韩理论电影院| 日本一区二区三区在线观看| 欧美一卡在线观看| 欧美视频一区二区三区四区| 不卡在线观看av| 成人国产精品免费| 国产精品资源网站| 国产一区二区不卡在线| 蜜桃av一区二区三区电影| 亚洲成人激情社区| 一区二区三区在线视频观看58| 国产精品蜜臀av| 国产日本欧美一区二区| 精品国产乱码久久久久久久| 日韩一级完整毛片| 91精品在线一区二区| 欧美日韩高清影院| 欧美日韩成人综合| 欧美日韩激情一区二区三区| 在线这里只有精品| 色婷婷精品大视频在线蜜桃视频| 国产99久久久国产精品潘金| 国产69精品一区二区亚洲孕妇| 久久成人久久爱| 免费高清不卡av| 精品一二线国产| 国产成人综合在线观看| 国模无码大尺度一区二区三区| 久久成人麻豆午夜电影| 久久精品国产久精国产爱| 久久精品国产99国产精品| 婷婷久久综合九色综合伊人色| 亚洲va欧美va人人爽午夜| 天天影视涩香欲综合网 | 天天综合天天做天天综合| 亚洲一二三四区不卡| 亚洲成a人v欧美综合天堂下载| 亚洲3atv精品一区二区三区| 天天色图综合网| 激情偷乱视频一区二区三区| 国产精品996| 色综合久久久网| 在线不卡一区二区| 日韩欧美一区二区在线视频| 久久一日本道色综合| 国产精品丝袜91| 亚洲一区二区三区四区在线观看 | 亚洲国产综合在线| 婷婷成人综合网| 韩国成人在线视频| 91麻豆免费看| 欧美三级午夜理伦三级中视频| 在线成人免费观看| 国产日韩视频一区二区三区| 亚洲丝袜美腿综合| 日本免费在线视频不卡一不卡二| 国产精品影视在线| 欧美日韩日日摸| 久久综合色婷婷| 亚洲自拍都市欧美小说| 黄色精品一二区| 欧美伊人久久久久久久久影院| 欧美一级日韩免费不卡| 国产精品久久久久久久久免费樱桃 | 丝袜诱惑亚洲看片| 国产成人免费在线观看| 欧美精品一二三四| 国产精品嫩草99a| 精品一区二区在线播放| 一本一本大道香蕉久在线精品 | 亚洲欧洲av在线| 蜜臀久久99精品久久久久宅男| 不卡电影一区二区三区| 欧美一级艳片视频免费观看| 亚洲精品第一国产综合野| 国产二区国产一区在线观看| 欧美日韩国产高清一区二区三区| 中文字幕免费在线观看视频一区| 日本欧美一区二区| 色狠狠色狠狠综合| 国产精品情趣视频| 极品美女销魂一区二区三区免费| 欧美偷拍一区二区| 亚洲色大成网站www久久九九| 国产在线不卡视频| 日韩欧美亚洲一区二区| 亚洲国产欧美一区二区三区丁香婷| 国产iv一区二区三区| 欧美mv和日韩mv国产网站| 丝袜a∨在线一区二区三区不卡| 不卡av电影在线播放| 久久久综合视频| 久久69国产一区二区蜜臀| 欧美精品欧美精品系列| 一区二区三区高清在线| a在线欧美一区| 国产精品短视频| 成人免费不卡视频| 国产午夜精品一区二区三区嫩草| 日本aⅴ亚洲精品中文乱码| 欧美久久婷婷综合色| 亚洲成人免费影院| 欧美日韩一区二区在线视频| 亚洲一区二区三区四区五区中文 | 欧美区一区二区三区| 亚洲国产日韩在线一区模特| 91免费视频大全| 亚洲欧美成aⅴ人在线观看 | 欧美日韩国产乱码电影| 午夜天堂影视香蕉久久| 欧美日韩国产一级片| 天堂va蜜桃一区二区三区漫画版| 欧美日韩精品欧美日韩精品| 丝袜国产日韩另类美女| 欧美一级日韩一级| 久久99久久久欧美国产| 欧美精品一区二区三区久久久| 麻豆国产一区二区| 久久久亚洲精华液精华液精华液| 国产精品123区| 国产欧美日韩视频一区二区| 成人性生交大片| 亚洲欧美国产三级| 欧美日韩在线播放一区| 蜜臀国产一区二区三区在线播放| 日韩免费看的电影| 国产福利视频一区二区三区| 国产精品无码永久免费888| 成人久久久精品乱码一区二区三区| 国产精品理论在线观看| 91亚洲永久精品| 亚洲第一成年网| 欧美va亚洲va香蕉在线| 菠萝蜜视频在线观看一区| 成人免费一区二区三区视频| 欧美日韩国产影片| 精品一区二区在线看| 亚洲国产高清不卡| 91高清视频在线| 精品一区二区三区日韩| 中文字幕在线不卡| 91精品国产91久久久久久最新毛片 | 欧美午夜理伦三级在线观看| 久久成人免费日本黄色|