今天小编继续给大家推荐优秀的Python第三方可视化绘制工具包,这次小编给大家推荐的为Python-mpl-chord-diagram包,顾名思义,此包为基于Matplotlib绘制和弦图(Chord Diagram),下面小编就详细介绍一下和弦图以及使用该包绘制和弦图的步骤,内容包括:
和弦图(Chord Diagram) 是一种表示实体之间相互关系的图图表类型,和弦图由节点分段和弧形的边构成,节点围绕着圆周分布,点与点之间以弧线或贝塞尔曲线彼此连接以显示当中关系,然后再给每个连接分配数值(通过每个圆弧的大小比例表示)。此外,也可以用颜色将数据分成不同类别,有助于进行比较和区分。示意图如下:
和弦图示意图(来源于网络)
关于和弦图具体的数值表示可通过如下这幅图得到充分解释:
和弦图数值表示(来源于网络,侵删)
Python基础绘图库-Matplotlib本身没有提供绘制和弦图绘制函数,mpl-chord-diagram库就可以完美解决这个问题,下面通过几个样例了解一下该库的具体绘制过程,如下:
from mpl_chord_diagram import chord_diagram
flux_data = np.array([
[0, 5, 6, 4, 7, 4],
[5, 0, 5, 4, 6, 5],
[6, 5, 0, 4, 5, 5],
[4, 4, 4, 0, 5, 5],
[7, 6, 5, 5, 0, 4],
[4, 5, 5, 5, 4, 0],
])
names = ["A","B","C","D","E","F"]
fig,ax = plt.subplots(figsize=(4,3.5),dpi=100,facecolor="w")
chord_diagram = chord_diagram(mat=flux_data,names=names,alpha=.8,ax=ax)
plt.tight_layout()
Example01 Of mpl_chord_diagram
设置参数chord_diagram函数中use_gradient=True即可绘制渐变色填充和同一和弦图边颜色,结果如下:
Example02 Of mpl_chord_diagram
from mpl_chord_diagram import chord_diagram
flux = chord_df01_matx.values
names = chord_df01_matx.columns.to_list()
colors = color_list[:len(names)]
fig,ax = plt.subplots(figsize=(4,3.5),dpi=100,facecolor="w")
chord_diagram(flux,names,chordwidth=.5,width=.05,fontsize=9,ax=ax)
plt.tight_layout()
Example02 Of mpl_chord_diagram
更多详细案例和绘制参数细节设置,可参考:Python-mpl_chord_diagram库官网[1]
对于和弦图来说,交互设计往往是必要的。加入高亮、数据标签等功能,可以让读者更容易进行阅读图表、进行自由探索。Python语言中,可使用Plotly和Bokeh库实现交互式和弦图绘制,下面为两个包绘制示例。
Example of Plotly make
具体交互样式可查看:Plotly 交互式和弦图样例[2]
Example of Plotly make
具体交互样式可查看:Bokeh交互式和弦图样例[3]
今天这边推文小编介绍了绘制静态和弦图的绘图工具-mpl-chord-diagram,基于Matplotlib绘制,更倾向于在学术论文中展示和弦图结果。
[1]
Python-mpl_chord_diagram库官网: https://github.com/tfardet/mpl_chord_diagram。
[2]
Plotly 交互式和弦图样例: https://plotly.com/python/v3/filled-chord-diagram/。
[3]
Bokeh交互式和弦图样例: https://holoviews.org/gallery/demos/bokeh/route_chord.html#demos-bokeh-gallery-route-chord。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有