我已经让我的饼图工作,但我注意到实际图表的文本框似乎不能正常工作。他们只是聚集在一起,所以我想知道有没有办法让我把标签移到中间的白色圆圈,并在旁边有匹配的颜色吗?在
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();
下面是一些示例数据以重现您的问题:
样本数据:
这将导致以下情节:
使用图例
打印时不要打印百分比或标签,然后创建一个放在旁边的图例:
^{pr2}$旋转标签:
创建标签并使用
^{3}$rotatelabels=True
。尽管在很多情况下,这可能仍然显得局促。在相关问题 更多 >
编程相关推荐