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

python Matplotlib底圖中鼠標(biāo)滑過顯示隱藏內(nèi)容的實(shí)例代碼

 更新時(shí)間:2019年07月31日 10:56:17   作者:lisa丶  
這篇文章主要介紹了python Matplotlib底圖中鼠標(biāo)滑過顯示隱藏內(nèi)容,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

在使用Matplotlib畫圖過程中,有些內(nèi)容必須鼠標(biāo)點(diǎn)擊或者劃過才可以顯示,這個(gè)問題可以依賴于annotate(s='str' ,xy=(x,y) ,xytext=(l1,l2) ,..)這個(gè)函數(shù),其中s 為注釋文本內(nèi)容 , xy 為被注釋的坐標(biāo)點(diǎn), xytext 為注釋文字的坐標(biāo)位置,其他參數(shù)可自行百度哈。當(dāng)鼠標(biāo)滑過時(shí)候,將其設(shè)置為可見,默認(rèn)情況下為隱藏。下面是一個(gè)小例子:

# -*- coding: UTF-8 -*-
import matplotlib.pyplot as plt
fig = plt.figure()
po_annotation = []
for i in range(0, 10):
  x = i
  y = x**2
  point, = plt.plot(x, y, 'o')
  annotation = plt.annotate(('x='+str(x), 'y='+str(y)), xy=(x+0.1, y+0.1), xycoords='data', xytext=(x+0.7, y+0.7),
                textcoords='data', horizontalalignment="left",
                arrowprops=dict(arrowstyle="simple",connectionstyle="arc3,rad=-0.1"),
                bbox=dict(boxstyle="round", facecolor="w",edgecolor="0.5", alpha=0.9)
                )
  annotation.set_visible(False)
  po_annotation.append([point, annotation])
def on_move(event):
  visibility_changed = False
  for point, annotation in po_annotation:
    should_be_visible = (point.contains(event)[0] == True)
    # print(point.contains(event)[0])
    if should_be_visible != annotation.get_visible():
      visibility_changed = True
      annotation.set_visible(should_be_visible)
  if visibility_changed:
    plt.draw()
on_move_id = fig.canvas.mpl_connect('motion_notify_event', on_move)
plt.show()

主要思路為:

•創(chuàng)建[點(diǎn),注釋]對(duì)的列表,默認(rèn)情況下,注釋不可見

•每次檢測(cè)到鼠標(biāo)移動(dòng)時(shí),都會(huì)注冊(cè)一個(gè)函數(shù)“on_move”
•on_move函數(shù)遍歷每個(gè)點(diǎn)和注釋,如果鼠標(biāo)現(xiàn)在位于其中一個(gè)點(diǎn)上,則使其關(guān)聯(lián)的注釋可見,如果不是,則使其不可見。

運(yùn)行出來(lái)的效果為: 當(dāng)鼠標(biāo)滑過時(shí),可以顯示其相應(yīng)坐標(biāo):

總結(jié)

以上所述是小編給大家介紹的python Matplotlib底圖中鼠標(biāo)滑過顯示隱藏內(nèi)容的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

最新評(píng)論

东台市| 慈利县| 德昌县| 桃源县| 大连市| 黎川县| 郸城县| 鄂州市| 依安县| 乌拉特后旗| 共和县| 成武县| 玉林市| 兴化市| 伊宁县| 信阳市| 固镇县| 丹阳市| 维西| 扶余县| 新宾| 鹿邑县| 抚松县| 贵定县| 广德县| 富川| 阳朔县| 吉林市| 桑日县| 五河县| 越西县| 泗阳县| 彭州市| 武邑县| 四会市| 奉贤区| 吴桥县| 吉水县| 望城县| 余江县| 剑阁县|