gpt4 book ai didi

python - Python 中的圆形箭头流程图

转载 作者:行者123 更新时间:2023-11-30 23:11:41 27 4
gpt4 key购买 nike

如何在Python中制作一个带有三个V形(或箭头)的圆形箭头流程图,如下图所示? figure

最佳答案

事实证明matplotlib有一个模块Sankey这将允许创建一个圆形箭头流程图。执行此操作的 python 代码如下:

import matplotlib.pyplot as plt
from matplotlib.sankey import Sankey

fontsize= 20
def circle(filename):
color = 'w'
pos = [2, 1]
fig = plt.figure(figsize=(8, 9))
ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[], frameon=False)
sankey = Sankey(ax=ax, gap=0.5, scale=1.0/pos[0])

sankey.add(patchlabel='\nFirst', facecolor='darkslateblue',
flows=[pos[1], -pos[1]],
labels=[None, None],
pathlengths=[0.5, 0.25],
orientations=[-1, -1], connect=(1, 0))
sankey.add(patchlabel='\n\n\n\n\n\nSecond', facecolor='blueviolet',
flows=[pos[1], -pos[1]],
labels=[None, None],
pathlengths=[0.5, 0.25],
orientations=[0, -1], prior = 0, connect=(1, 0))
sankey.add( facecolor='cornflowerblue',
flows=[pos[1], -pos[1]],
labels=[None, None],
pathlengths=[0.22, 0.75],
orientations=[0, -1], prior = 1, connect=(1, 0))


add_horizontal_text(ax, color)
diagrams = sankey.finish()
for diagram in diagrams:
diagram.text.set_fontweight('bold')
diagram.text.set_fontsize(fontsize)
diagram.text.set_color(color)

diagrams[1].text.set_fontsize(fontsize-2)
plt.savefig(filename)

return

def add_horizontal_text(ax, color):
x = -0.5
y = -1.68
offset = .1
ax.text(x, y, 'Third', fontsize=fontsize, weight='bold', ha='center', color=color)
return

circle('CircularArrow.png')

关于python - Python 中的圆形箭头流程图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30114067/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com