python xycoords_python可视化节点关系(三):matplotlib(2)鼠标交互

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实现鼠标交互

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="

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值