【问题标题】:Python - How can you plot a data histogram?Python - 你如何绘制数据直方图?
【发布时间】:2019-11-08 10:24:39
【问题描述】:

我正在寻找绘制日期直方图。我有一个熊猫数据框如下:

Creation Date  Profile_ID Count
2016-06-01            150
2016-06-03            3
2016-06-04            20 

如何定义直方图的 x 轴和 y 轴,以便绘制每个日期新创建的配置文件 ID 的数量图?

【问题讨论】:

    标签: python dataframe histogram


    【解决方案1】:

    试试:

    import matplotlib.pyplot as plt
    ax = df.plot.bar(y='Profile_ID Count')
    plt.show()
    

    【讨论】:

      【解决方案2】:
      # Importing the requisite libraries
      import pandas as pd
      import matplotlib.pyplot as plt
      
      # Creating the DataFrame
      df = pd.DataFrame({'Creation Date':['2016-06-01','2016-06-03','2016-06-04'],'Profile_ID Count':[150,3,20]})
      
      # Creating the bar chart below.
      fig, ax = plt.subplots()
      ax.bar(df['Creation Date'],df['Profile_ID Count'], color='red', width = 0.5)   
      fig.autofmt_xdate()   # This tilts the dates displayed along X-axis.
      ax.set_title('Creation Date vs. Profile ID Count')
      ax.set_xlabel('Creation Date')
      ax.set_ylabel('Profile ID Count')
      plt.show()
      

      【讨论】:

        猜你喜欢
        • 2019-04-20
        • 1970-01-01
        • 1970-01-01
        • 2018-05-23
        • 2020-03-14
        • 1970-01-01
        • 2023-03-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多