2017-09-26 64 views
0

我有一個情節,第5個條錯誤地放置在第4個條的旁邊。我應該改變什麼? 我small_ax_0大熊貓據幀看起來是這樣的:將最後一個柱狀圖刻度標籤移動到條的左側

INDEX 0 
0  1 5.0 
1 10001 4.0 
2 20001 5.0 
3 30001 5.0 
4 40001 5.0 
5 50001 4.0 
6 60001 1.0 
7 70001 4.0 
8 80001 0.0 
9 90001 4.0 

這裏是我的代碼:

plt.hist(small_ax_0[0]) 
plt.tick_params(axis='both', which='major', labelsize=100) 
plt.tick_params(axis='both', which='minor', labelsize=100) 
plt.xlabel('Position', fontsize=100) 
plt.ylabel('Frequency', fontsize=100) 
plt.title('My Plot', fontsize = 150) ## 
plt.grid(b=True, which='major', color='grey', linestyle='dotted') 
plt.xticks(rotation = 45) 
plt.show() 

enter image description here

回答

0

默認情況下,hist收益10個箱,沿着你的數據的範圍等距。所以在這種情況下,數據範圍從0到5,分箱間距爲0.5。如果你只是想繪製每個數字出現的次數,我建議使用np.unique()和使用bar情節:

import numpy as np 
nums, freq = np.unique(small_ax_0[0], return_counts=True) 
plt.bar(nums, freq) 

,你會得到一個數字,其中條互相纏繞數居中。

enter image description here

1

大熊貓visualization

df['0'].value_counts().sort_index().plot(kind='bar') 

enter image description here