【发布时间】:2021-04-21 02:33:19
【问题描述】:
这些是我的专栏:
SeniorCitizen Partner Dependent
Yes Yes No
No Yes No
No No Yes
Yes No No
我想在单个图形或工作表中绘制所有这些列的单独饼图。这是我的代码:
ax1 = df2['SeniorCitizen'].value_counts().plot(kind='pie', figsize=(5,5), fontsize=10,
labels = ['No', 'Yes'], autopct='%1.0f%%')
ax1.set_title('% of Senior Citizens', fontsize = 12)
plt.show()
ax2 = df2['Partner'].value_counts().plot(kind='pie', figsize=(5,5), fontsize=10, autopct='%1.0f%%')
ax2.set_title('% of People with and without partner', fontsize = 12)
plt.show()
ax2 = df2['Dependents'].value_counts().plot(kind='pie', figsize=(5,5), fontsize=10, autopct='%1.0f%%')
ax2.set_title('% of People with and without dependent', fontsize = 12)
plt.show()
输出一个接一个地出现在一条直线上。我认为有一个叫做 subplots 的概念,可以让它以水平的形式出现。
【问题讨论】:
标签: python pandas matplotlib jupyter-notebook