【问题标题】:How to make group bars on jupyter notebook?如何在 jupyter notebook 上制作群组栏?
【发布时间】:2021-12-06 22:30:00
【问题描述】:

我正在尝试在我的 jupyter 笔记本上的同一个图上绘制多个条形图。但是,由于某种原因,它不能在笔记本上运行,但它可以在普通的 python 编辑器上运行。这是我使用的代码。

import matplotlib.pyplot as plt
plt.bar(['A','B','C'],[72,73,88])
plt.bar(['A','B','C'],[98,77,98])
plt.show()

我们将不胜感激。

(编辑) 我正在我的 jupyter 笔记本上寻找这样的东西。

【问题讨论】:

  • @TrentonMcKinney 很抱歉,如果我以错误的方式提出了我的问题。但它就像我刚刚添加的图片上的那个。
  • 问题应该是,如何制作分组条
  • df = pd.DataFrame({'boy': [72,73,88], 'girl': [98,77,98]}, index= ['A','B','C']) 然后df.plot(kind='bar', rot=0)
  • 这能回答你的问题吗? How to create a grouped bar plot from lists
  • 感谢@TrentonMcKinney。我已经更正了这个问题。

标签: python matplotlib bar-chart


【解决方案1】:

我假设您希望将两个条形图并排放置。所以给你:

import matplotlib.pyplot as plt
fig,axs = plt.subplots(1,2)
axs[0].bar(['A','B','C'],[72,73,88])
axs[1].bar(['A','B','C'],[98,77,98])
plt.show()

【讨论】:

    猜你喜欢
    • 2021-03-28
    • 2020-10-31
    • 2018-04-04
    • 2016-05-24
    • 1970-01-01
    • 2018-05-22
    • 2016-08-13
    • 2019-10-14
    • 2018-01-28
    相关资源
    最近更新 更多