【问题标题】:How to plot Histogram on specific data如何在特定数据上绘制直方图
【发布时间】:2020-07-08 17:08:53
【问题描述】:

我正在阅读 CSV 文件:

 Notation Level   RFResult   PRIResult   PDResult  Total Result
 AAA       1       1.23        0           2         3.23
 AAA       1       3.4         1           0         4.4
 BBB       2       0.26        1           1.42      2.68
 BBB       2       0.73        1           1.3       3.03
 CCC       3       0.30        0           2.73      3.03
 DDD       4       0.25        1           1.50      2.75
 ...
 ...

这里是代码

import pandas as pd

df = pd.rad_csv('home\NewFiles\Files.csv')
Notation = df['Notation']
Level = df['Level']
RFResult = df['RFResult']
PRIResult = df['PRIResult']
PDResult = df['PDResult']

df.groupby('Level').plot(kind='bar')

上面的代码给了我四个不同的数字。我想改变以下几点:

  1. 我不想在图表中显示 LevelTotal Results 条形图。我应该如何删除它?

  2. 另外,我应该如何标记 xaxis 和 yaxis 以及每个图的标题。所以为此,我想给情节的标题是“层数”。

【问题讨论】:

    标签: python-3.x matplotlib histogram


    【解决方案1】:

    要绘制使用以下代码...

    import pandas as pd
    import matplotlib.pyplot as plt
    
    df = pd.read_csv('home\NewFiles\Files.csv')
    plt.hist((df['RFResult'],df['PRIResult'],df['PDResult']),bins=10)
    plt.title('Level Number')
    plt.xlabel('Label name')
    plt.ylabel('Label name')
    plt.plot()
    
    
      
    

    【讨论】:

      【解决方案2】:

      你可以这样做:

      import pandas as pd
      import matplotlib.pyplot as plt
          
      df = pd.read_csv('home\NewFiles\Files.csv')
      
      df.plot(kind='hist', y = ['RFResult', 'PRIResult', 'PDResult'], bins=20)
      
      plt.title('level numbers')
      plt.xlabel('X-Label')
      plt.ylabel('Y-Label')
      

      请记住,情节是由pandas 调用的,但基于matplotlib。所以你可以传递额外的参数!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-23
        • 1970-01-01
        • 2017-08-13
        • 1970-01-01
        • 2023-03-08
        • 2020-10-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多