问题描述
我有什么似乎是一个简单的任务,但我不知道如何和从哪里开始。我目前拥有的是在一幅图上显示的一系列子图。现在我想在每个子图上添加/连接一个事件处理程序,这样当用户点击其中一个子图时,所选择的图将在单独的图形/窗口中打开。我想知道这是否可能,如果有人可以制定一个简单的代码来说明如何做到这一点。
我还应该提到,我正在使用和感兴趣的唯一的情节是色彩(使用imshow())。
您应阅读教程。
基本上你需要定义一个需要一个争论事件
的函数,然后把它附加到你的人物的画布上:
$ $ $ $ $ $ $ $ $ $ $如果event.inaxes不是没有
ax = event.inaxes
#你现在有轴对象因为用户点击
#,您可以使用ax.children()来确定哪个img艺术家在这个
#轴中并从中提取数据
cid =无花果
I have what seems to be a simple task yet I am not sure how and where to start. What I currently have is a series of subplots displayed on one figure. Now I want to add/connect an event handler on each subplot, such that when the user clicks on one of the subplots the plot that was selected would be opened in a separate figure/window.
I want to know if this is possible and if someone could formulate a small simple code to illustrate how this can be done.I should also mention that the only type of plot that I am using and interested in are colormaps (using imshow()).
You should read this tutorial.
Basically you need to define function which takes one arguement event
and then attach it to your figure's canvas:
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)
这篇关于事件连接和子图在matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!