【问题标题】:show all pie chart together in pandas在熊猫中一起显示所有饼图
【发布时间】:2020-10-15 07:31:42
【问题描述】:

我有五个数据框

               pt       car     walk    bike
Normal day     28.80    36.82   30.83   3.55
start          28.82    36.83   30.80   3.55
Equilibrium    28.51    36.95   30.98   3.56
Medium         31.74    33.80   32.23   2.23
Equilibrium2   32.06    34.04   30.78   3.12

我用下面的代码

fig, axes = plt.subplots(3, 3, figsize=(14, 10))
colors = ['yellowgreen','lightcoral','pink','lightskyblue']

for i, (idx, row) in enumerate(df.iterrows()):
    ax = axes[i // 3, i % 3]
    row = row[row.gt(row.sum() * .001)]
    #ax.pie(row, autopct='%1.1f%%',startangle=30, color=colors)
    ax.pie(row,  colors=colors,
                 autopct='%0.01f%%', startangle=30, pctdistance=0.7, radius=1)
    ax.set_title(idx)

    
#fig.legend(('pt','transit_walk','car', 'walk', 'bike'), prop={'size': 8}, title = 'Scenarios')
fig.legend(labels=df.columns,fontsize= 14,loc="center right")
fig.subplots_adjust(hspace=0.1, wspace=0.01)

我制作了这个图:

但是,我想要这张图片:

如何将它们结合起来?

【问题讨论】:

标签: pandas dataframe pie-chart


【解决方案1】:

试试这样的:

fig, ax = plt.subplots()
colors = ['yellowgreen','lightcoral','pink','lightskyblue']
size = 1/len(df.index)
yticks = []
yticklabels = []
for i, (idx, row) in enumerate(df.iterrows()):
    row = row[row.gt(row.sum() * .001)]
    ax.pie(row, 
        colors=colors, 
        radius=1-size*i,
        autopct='%0.01f%%',
        startangle=90,
        pctdistance=0.9,
        wedgeprops=dict(width=size),
        counterclock=False)
    yticks.append(i*size)
    yticklabels.append(idx)

ax.set_yticks(yticks)
ax.set_yticklabels(yticklabels)
fig.legend(labels=df.columns,fontsize= 14,loc="center right")

【讨论】:

    猜你喜欢
    • 2023-02-04
    • 1970-01-01
    • 2020-07-18
    • 2017-01-14
    • 2019-01-22
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多