【发布时间】:2021-04-20 17:18:56
【问题描述】:
数据:
import numpy as np
import matplotlib.pyplot as plt
labels=['Cat','Dog','Human','Rabbit']
data1=[35,80,2,20]
data2=[5,3,80,8]
我正在使用上述数据绘制嵌套饼图:
size=0.3
fig,ax=plt.subplots(figsize=(20,10))
cmap=plt.get_cmap('tab20c')
outer_colors=cmap(np.arange(0,3)*5)
inner_colors=cmap(np.arange(0,3)*5)
ax.pie(x=data1,autopct='%.2f%%',shadow=True,startangle=180,radius=1,wedgeprops={'width':size,'edgecolor':'c'},colors=outer_colors)
ax.pie(x=data2,autopct='%.2f%%',shadow=True,startangle=180,radius=0.5,wedgeprops={'width':size,'edgecolor':'c'},colors=inner_colors)
plt.title('Good vs Bad Pets',fontsize=18,weight='bold')
plt.legend(labels,fontsize=15)
plt.show()
以上代码的输出:
我的问题是:
从上图我们可以看到,在内部饼图中,值(%)也在图中,但它不在外部图中。
那么我该怎么做呢?
预期输出:
【问题讨论】:
标签: python matplotlib data-visualization