[英]matplotlib histogram bins shifted and individual data label
我正在使用 Matplotlib 為以下數據創建直方圖:
df['overall'].value_counts(): 5.0 108602 4.0 39974 3.0 21436 1.0 13269 2.0 11059
我使用了以下代碼:
plt.hist(df['overall']) plt.xlabel('Class') plt.ylabel('Amount')
我的情節是這樣的:
為什么我的垃圾箱移動了,有沒有辦法只顯示 1.0、2.0、3.0、4.0、5.0 和上面的垃圾箱? 其次,我如何獲得總金額和相對金額的數據標簽?
非常感謝您的高級:)
盡管您可以使用直方圖,但您必須小心選擇的 bin 大小(默認情況下,matplotlib 將創建 10 個等寬的 bin)。
我寧願認為您想繪制條形圖,而不是直方圖:
data = df['overall'].value_counts() fig, ax = plt.subplots() ax.bar(data.index, data.values)
[英]Matplotlib polar histogram has shifted bins
[英]Matplotlib histogram shifted xticks
[英]How to choose bins in matplotlib histogram
[英]Matplotlib Histogram: Green and Blue Bins
[英]Matplotlib Histogram Bins Include/Exclude
[英]Excluding a certain range of bins in a matplotlib histogram?
[英]Graph matplotlib to show total count in the histogram bins
[英]Histogram `bins` must increase monotonically matplotlib
[英]python matplotlib: label in histogram
[英]Matplotlib: How to make a histogram with bins of equal area?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.