Matplotlib 在绘画bar时, 鼠标响应点击 bar 的消息

官方教程:

http://urania.udea.edu.co/sitios/astronomia-2.0/pages/descargas.rs/files/descargasdt5vi/Cursos/CursosElectivos/FisicaAstrofisicaComputacional/2009-2/Documentacion/matplotlib/examples/event_handling/pick_event_demo.html


注意:

1. 在 bar()调用时要设至 picker = True

2.   for label in ax1.get_xticklabels(): 
                label.set_picker(True)

3. 定义回调函数           

            def _onpick1(event):
                if isinstance(event.artist, Rectangle):
                    rect = event.artist
                    #matplotlib中Rectangle的x就是index
                    index = rect.get_x()
                    print(index)

4.注册回调函数            

fig.canvas.mpl_connect('pick_event', _onpick1)

posted on 2014-11-11 22:24  norsd  阅读(528)  评论(0编辑  收藏  举报

导航