use*_*948 3 python matplotlib event-handling color-mapping
我有一个似乎是一个简单的任务,但我不知道如何以及从哪里开始.我目前拥有的是一个图上显示的一系列子图.现在我想在每个子图上添加/连接一个事件处理程序,这样当用户点击其中一个子图时,所选的图将在一个单独的图/窗口中打开.
我想知道这是否可行,是否有人可以制定一个简单的小代码来说明如何做到这一点.我还要提一下,我使用和感兴趣的唯一一种情节是彩色地图(使用imshow()).
你应该阅读本教程.
基本上你需要定义一个函数,它接受一个争论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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3561 次 |
| 最近记录: |