此问题已在此处有答案:
Arrows between subplots(1个答案)
3小时前关闭
我目前有两个子图,一个饼图和一个条形图,我想知道是否有一种方法可以添加一条线或箭头来表示饼图的红色部分是指堆叠条形图。
从这里:
对此:
这是我目前为止的代码:
opfig, (ax1, ax2) = plt.subplots(1, 2, figsize = (12,6), dpi=80)
percentage = operator['Percentage']
labels = operator['Operator']
explode = (0,0,0,0.1)
label = [f'{lab}, {per:0.1f}%' for lab, per in zip(labels,percentage*100)]
ax1.pie(operator['Count'], explode = explode)
ax1.legend(labels=label, title='Operator Type')
militaryPer = military['Percentage']
militaryLab = military["Military"]
bottom = 1
width = 0.2
for j, (height, label) in enumerate([*zip(militaryPer, militaryLab)]):
bottom -= height
bc = ax2.bar(0, height, width, bottom = bottom, color="C0", label=label, alpha=0.1+0.25*j)
ax2.bar_label(bc, labels=[F"{height:.0%}"], label_type='center')
ax2.set_title('Military Operators')
ax2.legend(loc='lower right', prop={'size': 10}, borderpad=1, framealpha=0.9)
ax2.axis('off')
ax2.set_xlim(-1.5 * width, 1.5 * width)
plt.show()
1条答案
按热度按时间mxg2im7a1#
您可以使用Matplotlib添加箭头:
可以根据需要修改坐标和箭头特性,以便根据特定的可视化效果正确定位直线或箭头。