实现鼠标交互
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="