实现鼠标交互
1. 实现鼠标点击节点高亮
直接上代码:
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import numpy as np
fig, ax = plt.subplots(figsize=(10,10))
node_pos = [(1, 0), (0, 1), (2,1), (1,2)]
bbox_args = dict(boxstyle="round", fc="0.8")
arrow_args = dict(arrowstyle="->")
an1 = plt.annotate(s="Test 1\n(node1,node2)\n(node3,node4,node5)\n\n\n", xy=node_pos[0], xycoords="data",
va="center", ha="center",
bbox=dict(boxstyle="round", fc="w", facecolor='green'))
an2 = plt.annotate(s="Test 2\n(node1,node2)", xy=node_pos[1], xycoords="data",
va="center", ha="center",
bbox=dict(boxstyle="round", fc="w", facecolor='green'))
arrow1 = plt.annotate('', xy=(0, 0), xycoords=an1,
xytext=(0, 0), textcoords=an2, # an1 -> an2
size=20, ha="center", va="

这篇博客介绍了如何使用Python的matplotlib库创建节点关系图,并实现鼠标交互功能。内容包括:1) 鼠标点击节点时,节点高亮显示;2) 鼠标悬停在节点上时,显示节点信息。博客中提供了详细的代码示例,强调了在回调函数中更新参数和处理鼠标事件的重要性。
最低0.47元/天 解锁文章
4253

被折叠的 条评论
为什么被折叠?



