<tfoot id='gwLUC'></tfoot>

<small id='gwLUC'></small><noframes id='gwLUC'>

    • <bdo id='gwLUC'></bdo><ul id='gwLUC'></ul>

  1. <legend id='gwLUC'><style id='gwLUC'><dir id='gwLUC'><q id='gwLUC'></q></dir></style></legend>
  2. <i id='gwLUC'><tr id='gwLUC'><dt id='gwLUC'><q id='gwLUC'><span id='gwLUC'><b id='gwLUC'><form id='gwLUC'><ins id='gwLUC'></ins><ul id='gwLUC'></ul><sub id='gwLUC'></sub></form><legend id='gwLUC'></legend><bdo id='gwLUC'><pre id='gwLUC'><center id='gwLUC'></center></pre></bdo></b><th id='gwLUC'></th></span></q></dt></tr></i><div id='gwLUC'><tfoot id='gwLUC'></tfoot><dl id='gwLUC'><fieldset id='gwLUC'></fieldset></dl></div>

    1. Python 和 Matplotlib 以及鼠标悬停注释

      时间:2023-09-14
      <tfoot id='Mxk2C'></tfoot>
        • <legend id='Mxk2C'><style id='Mxk2C'><dir id='Mxk2C'><q id='Mxk2C'></q></dir></style></legend>
          • <bdo id='Mxk2C'></bdo><ul id='Mxk2C'></ul>

                <tbody id='Mxk2C'></tbody>

                <i id='Mxk2C'><tr id='Mxk2C'><dt id='Mxk2C'><q id='Mxk2C'><span id='Mxk2C'><b id='Mxk2C'><form id='Mxk2C'><ins id='Mxk2C'></ins><ul id='Mxk2C'></ul><sub id='Mxk2C'></sub></form><legend id='Mxk2C'></legend><bdo id='Mxk2C'><pre id='Mxk2C'><center id='Mxk2C'></center></pre></bdo></b><th id='Mxk2C'></th></span></q></dt></tr></i><div id='Mxk2C'><tfoot id='Mxk2C'></tfoot><dl id='Mxk2C'><fieldset id='Mxk2C'></fieldset></dl></div>

                <small id='Mxk2C'></small><noframes id='Mxk2C'>

                本文介绍了Python 和 Matplotlib 以及鼠标悬停注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                当我单击 Basemap Matplotlib Plot 中的一个点时,我目前正在使用此代码在地图上弹出注释.

                I am currently employing this code to have pop up annotatations on a map when i click on a point in a Basemap Matplotlib Plot.

                dcc = DataCursor(self.figure.gca())
                self.figure.canvas.mpl_connect('pick_event',dcc)
                plot_handle.set_picker(5)
                self.figure.canvas.draw()
                
                class DataCursor(object):
                
                    import matplotlib.pyplot as plt
                
                    text_template = 'x: %0.2f
                y: %0.2f' 
                    x, y = 0.0, 0.0 
                    xoffset, yoffset = -20 , 20
                    text_template = 'A: %s
                B: %s
                C: %s'
                
                
                    def __init__(self, ax): 
                        self.ax = ax 
                        self.annotation = ax.annotate(self.text_template,  
                                xy=(self.x, self.y), xytext=(0,0),
                                textcoords='axes fraction', ha='left', va='bottom', fontsize=10,
                                bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=1), 
                                arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0') 
                                ) 
                        self.annotation.set_visible(False)
                        self.annotation.draggable()
                
                
                    def __call__(self, event):
                
                        self.event = event 
                        self.x, self.y = event.mouseevent.xdata, event.mouseevent.ydata
                
                        if self.x is not None:
                            glim = pickle.load(open("ListA.py","rb"))
                            tlim = pickle.load(open("ListB.py","rb"))
                            vlim = pickle.load(open("ListC.py","rb"))
                            a = glim[event.ind[0]] # ['Name'][event.ind[0]]
                            b = tlim[event.ind[0]]
                            c = vlim[event.ind[0]]
                            temp_temp=self.text_template % (a, b, c)
                            if temp_temp == self.annotation.get_text() and self.annotation.get_visible(): 
                                self.annotation.set_visible(False) 
                                event.canvas.draw() 
                                return 
                            self.annotation.xy = self.x, self.y
                            self.annotation.set_text(self.text_template % (a, b, c))
                            self.annotation.set_visible(True)
                
                            event.canvas.draw()
                

                我想知道的是,如何使用鼠标悬停而不是单击某个点来显示注释?

                What I am wondering, is how to show the annotations using mouse hover rather than clicking on a point?

                我见过motion_notify_event",但是当我在绘图区域周围移动鼠标时,代码似乎出错了.有什么想法吗?

                I have seen "motion_notify_event" but it seems the code gets errors when i move the mouse around the plot area. Any Thoughts?

                推荐答案

                看看this question 和 demo:

                from matplotlib.pyplot import figure, show
                import numpy as npy
                from numpy.random import rand
                
                
                if 1: # picking on a scatter plot (matplotlib.collections.RegularPolyCollection)
                
                    x, y, c, s = rand(4, 100)
                    def onpick3(event):
                        ind = event.ind
                        print 'onpick3 scatter:', ind, npy.take(x, ind), npy.take(y, ind)
                
                    fig = figure()
                    ax1 = fig.add_subplot(111)
                    col = ax1.scatter(x, y, 100*s, c, picker=True)
                    #fig.savefig('pscoll.eps')
                    fig.canvas.mpl_connect('pick_event', onpick3)
                
                show()
                

                这篇关于Python 和 Matplotlib 以及鼠标悬停注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何按行计算百分比并注释 100% 堆积条 下一篇:matplotlib中换行的文本框?

                相关文章

                最新文章

                  <legend id='7Znjf'><style id='7Znjf'><dir id='7Znjf'><q id='7Znjf'></q></dir></style></legend>
                1. <small id='7Znjf'></small><noframes id='7Znjf'>

                    <bdo id='7Znjf'></bdo><ul id='7Znjf'></ul>
                  <i id='7Znjf'><tr id='7Znjf'><dt id='7Znjf'><q id='7Znjf'><span id='7Znjf'><b id='7Znjf'><form id='7Znjf'><ins id='7Znjf'></ins><ul id='7Znjf'></ul><sub id='7Znjf'></sub></form><legend id='7Znjf'></legend><bdo id='7Znjf'><pre id='7Znjf'><center id='7Znjf'></center></pre></bdo></b><th id='7Znjf'></th></span></q></dt></tr></i><div id='7Znjf'><tfoot id='7Znjf'></tfoot><dl id='7Znjf'><fieldset id='7Znjf'></fieldset></dl></div>

                    <tfoot id='7Znjf'></tfoot>