我想显示条形图但不能很好地工作

时间:2018-04-06 08:38:29

标签: python pandas matplotlib bar-chart

我有一个像这样的DataFrame(名称:df_buy_sum)。 这是Pandas DataFrame。

                            BUY
exec_date                      
2018-04-06 17:14:00    9.408225
2018-04-06 17:15:00   89.558326
2018-04-06 17:16:00   88.607791
2018-04-06 17:17:00  108.968230
2018-04-06 17:18:00   80.283624
2018-04-06 17:19:00   50.469037
2018-04-06 17:20:00   74.773105
2018-04-06 17:21:00  115.339747
2018-04-06 17:22:00   84.019508
2018-04-06 17:23:00   44.809346
2018-04-06 17:24:00   31.855530

我试图展示BarChart,但我无法做到。我只能显示折线图。

我写过,

fig = plt.figure()
ax = fig.add_subplot(111)
.
.
ax.bar(df_buy_sum.index,df_buy_sum['BUY'])

但是输出是这样的。

enter image description here

什么是失败的点,以及如何解决? 谢谢。

2 个答案:

答案 0 :(得分:0)

也许是这样的:

df_buy_sum.plot(kind='bar')

完整示例

import pandas as pd
from matplotlib import pyplot

d = pd.date_range('2007-04-25', periods=50)
s = pd.Series(range(50), index=d)
s.plot(kind='bar')
pyplot.show()

答案 1 :(得分:0)

您可以尝试使用figsize来增加条形图的大小。

fig = plt.figure(figsize=(6, 6)) #here you can increase window size of chart
ax = fig.gca() # define axis                   
ax.bar(df_buy_sum.index,df_buy_sum['BUY'])