【问题标题】:Event Connections and subplots in matplotlibmatplotlib 中的事件连接和子图
【发布时间】:2013-01-09 13:27:37
【问题描述】:

我有一个看似简单的任务,但我不知道如何以及从哪里开始。我目前拥有的是在一个图中显示的一系列子图。现在我想在每个子图上添加/连接一个事件处理程序,这样当用户单击其中一个子图时,选定的图将在单独的图形/窗口中打开。
我想知道这是否可能,以及是否有人可以制定一个简单的小代码来说明如何做到这一点。 我还应该提到,我正在使用和感兴趣的唯一绘图类型是颜色图(使用 imshow())。

【问题讨论】:

    标签: python event-handling matplotlib color-mapping


    【解决方案1】:

    您应该阅读this 教程。

    基本上你需要定义一个函数,它接受一个参数event,然后将它附加到你的图形画布上:

    def open_new_figure(event):
        if event.inaxes is not None:
            ax = event.inaxes
            # you now have the axes object for that the user clicked on
            # you can use ax.children() to figure out which img artist is in this
            # axes and extract the data from it
    
    cid = fig.canvas.mpl_connect('button_press_event', open_new_figure)
    

    【讨论】:

    • 非常感谢!您代码中的注释帮助我了解如何找到所需的轴。
    猜你喜欢
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多