matplot饼图:水平旋转标签 [英] matplot pie: rotate labels horizontally

查看:93
本文介绍了matplot饼图:水平旋转标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用matplot通过以下代码创建一个小量规:

Using matplot to create a little gauge with the code below:

    group_size=[10,10,10,10,10,50]
    labels=['AAAA','BBBB','CCCC','DDDD','EEEE','']
    fig, ax = plt.subplots()
    ax.axis('equal')
    pie = ax.pie(group_size, radius=2.2, colors=['k'] ,startangle=180,counterclock=False)
    pie2 = ax.pie([10,10,10,10,10,50], radius=2,  labeldistance=0.7, labels=labels, rotatelabels = 270,
startangle=180,counterclock=False)
    plt.show()

我正在尝试使标签水平移动并像这样与每个楔形的中点对齐(但要与楔形内部的文本对齐):

I am trying to get the labels to go horizontally and align with the midpoint of each wedge like this (but with the text inside the wedges):

使用rotatelabel = True,我得到以下信息:

Using rotatelabel=True, I get the following:

关于如何实现图形标签水平旋转的任何想法?

Any ideas on how I can achieve the horizontal rotation of the labels for the graph?

推荐答案

您需要手动旋转饼图标签.为此,您可以遍历标签并根据需要设置旋转角度.

You need to rotate the pie labels manually. To this end you may loop over the labels and set the rotation to your needs.

group_size=[10,10,10,10,10,50]
labels=['AAAA','BBBB','CCCC','DDDD','EEEE','']
fig, ax = plt.subplots()
ax.axis('equal')
pie = ax.pie(group_size, radius=2.2, colors=['k'] ,startangle=180,counterclock=False)
pie2 = ax.pie([10,10,10,10,10,50], radius=2,  labeldistance=0.9, labels=labels, 
              rotatelabels =True, startangle=180,counterclock=False)

plt.setp(pie2[1], rotation_mode="anchor", ha="center", va="center")
for tx in pie2[1]:
    rot = tx.get_rotation()
    tx.set_rotation(rot+90+(1-rot//180)*180)

plt.show()

这篇关于matplot饼图:水平旋转标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆