2017-09-26 32 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

相关问题