我有以下代码绘制两个饼图,一个在另一个下方。我想要的是将它们彼此相邻绘制。我如何使用以下信息做到这一点?
ax1=apr_prev.set_index('Previous').plot.pie(y='Previous_Counts', figsize=(8, 8), title="Top 10 Before", \
legend=False, autopct='%1.1f%%', shadow=True, startangle=0, explode=(0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0))
ax1.set_ylabel('')
ax2=apr_cur.set_index('Current').plot.pie(y='Current_Counts', figsize=(8, 8), title="Top 10 Current", \
legend=False, autopct='%1.1f%%', shadow=True, startangle=0, explode=(0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0))
ax2.set_ylabel('')
答案 0 :(得分:1)
您需要:
通过以下方式在所需布局中创建 2 个轴:
fig, (ax1, ax2) = plt.subplots(1, 2)
明确说明每个 pie
的状态,通过 ax
参数绘制它的位置。例如:
apr_prev.set_index('Previous').plot.pie(y='Previous_Counts', figsize=(8, 8),
title="Top 10 Before", legend=False, autopct='%1.1f%%', shadow=True, startangle=0,
explode=(0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0), ax=ax1)