小编Com*_*ent的帖子

Matplotlib - 将标签移动到饼图中间

我的饼图有效,但我注意到实际图表的文本框似乎没有正常工作.它们只是聚集在一起,所以我想知道有没有办法让我将标签移动到白色圆圈的中间位置,旁边是否有匹配的颜色?

crimeTypes = dict(crimeData["Crime type"].value_counts())

crimeType = []
totalAmount = []
numberOfCrimes = 14

for key in sorted(crimeTypes, key=crimeTypes.get, reverse=True):
    crimeType.append(key)
    totalAmount.append(crimeTypes.get(key))

crimeType_sample = crimeType[0:numberOfCrimes]
totalAmount_sample = totalAmount[0:numberOfCrimes]

fig1, ax1 = plt.subplots()
ax1.pie(totalAmount_sample, labels=crimeType_sample, autopct='%1.1f%%', shadow=False, startangle=90)
ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.
fig1 = plt.gcf()
fig1.set_size_inches(10,10)
circle = plt.Circle(xy=(0,0), radius=0.75, facecolor='white')
plt.gca().add_artist(circle)
plt.show();
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

python matplotlib pandas pie-chart

6
推荐指数
1
解决办法
408
查看次数

标签 统计

matplotlib ×1

pandas ×1

pie-chart ×1

python ×1