Python中的组合条形图 [英] Combined Bar plots in python

查看:170
本文介绍了Python中的组合条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分组为 dataframe 这就是:

I have a grouped dataframe which is this:

            Speed (mph)
Label Hour             
5     13      18.439730
      14      24.959555
      15      33.912493
7     13      23.397055
      14      18.497228
      15      33.493978
12    13      32.851146
      14      33.187193
      15      32.597150
14    13      14.491841
      14      12.397724
      15      19.581669
21    13      34.985289
      14      34.817009
      15      34.888187
26    13      35.813901
      14      36.622450
      15      36.540348
28    13      33.761174
      14      33.951116
      15      33.736014
29    13      34.545862
      14      34.227974
      15      34.435377

我试图绘制每条柱线按照它们的标签小时

I am trying to plot bar plots where each bar is grouped by their Label and Hour


  • 举例:
  • An example:

上图只是我在互联网上找到的一个例子。我并不需要线条和数字。

The above graph is just an example I found on the internet. I don't really need the lines and the numbers over the bars.

我试过这样的绘图:

I tried plotting like this:

newdf.plot.bar()
plt.show()

这给了我 -


  • 问题

  • Question

该图使得标签:5,小时:13,14,15 并且接近一致,然后是一些空格,然后是标签:7,小时: 13,14,15 靠近在一起等等?

How can I plot the graph so that Label:5,Hour:13,14,15 and close to gether, then some space and then Label:7,Hour:13,14,15 close together and so on?

推荐答案

看起来你需要将

df.unstack().plot.bar()
plt.show()

这篇关于Python中的组合条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆