Is there a parameter in matplotlib/pandas to have the Y axis of a histogram as percentage?

后端 未结 5 2103
野趣味
野趣味 2020-12-13 02:12

I would like to compare two histograms by having the Y axis show the percentage of each column from the overall dataset size instead of an absolute value. Is that possible?

5条回答
  •  情话喂你
    2020-12-13 02:43

    You can simplify the weighting using np.ones_like():

    df["ColumnName"].plot.hist(weights = np.ones_like(df.index) / len(df.index))
    
    • np.ones_like() is okay with the df.index structure
    • len(df.index) is faster for large DataFrames

提交回复
热议问题