【问题标题】:Use subplots for pie char and bar char pandas [duplicate]对饼图和条形图 Pandas 使用子图 [重复]
【发布时间】:2021-08-03 18:38:48
【问题描述】:

我正在尝试显示两个相邻的图表。饼图和条形图。 我的代码是:

import matplotlib.pyplot as plt
fig , ax = plt.subplots(nrows = 1, ncols = 2)
df['column'].value_counts().plot.pie()
df['column'].value_counts().plot.bar()
plt.show() 

这是输出:

有人可以帮帮我吗?

【问题讨论】:

    标签: python pandas matplotlib subplot figure


    【解决方案1】:

    将子图传递给绘图命令:

    fig , ax = plt.subplots(nrows = 1, ncols = 2)
    
    df['column'].value_counts().plot.pie(ax=ax[0])
    df['column'].value_counts().plot.bar(ax=ax[1])
    
    plt.show() 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-07
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多