【问题标题】:I want to show Bar Chart but can't work well我想显示条形图但不能正常工作
【发布时间】:2018-09-16 05:47:50
【问题描述】:

我有一个像这样的 DataFrame(name: df_buy_sum)。 这是熊猫数据框。

                            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'])

但是输出是这样的。

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

【问题讨论】:

    标签: python pandas matplotlib bar-chart


    【解决方案1】:

    您可以尝试使用 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'])
    

    【讨论】:

      【解决方案2】:

      可能是这样的:

      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()
      

      【讨论】:

      • 但是当我使用实时数据时,它不能很好地工作。我认为一个代码 ani = FuncAnimation(fig, plot, interval=120) plt.show() 它做了一些东西,不能显示 BarChar。
      猜你喜欢
      • 2019-12-22
      • 1970-01-01
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-16
      • 1970-01-01
      • 2012-06-09
      相关资源
      最近更新 更多