我正在尝试使用searborn绘制水平条形图。但是我希望y轴显示数据的两个小数点,但是只显示数据中存在的值,,例如0.96
,0.93
以下是我所拥有的:
df=pd.read_excel('file.xlsx', sheet_name='all')
print(df['digits'])
1. 0.96270
1 0.93870
2 0.93610
3 0.69610
4 0.61250
5 0.61280
6 0.52965
7 0.50520
sns.histplot(y=df['digits'])
plt.xlabel("frequency", fontsize=15)
plt.ylabel("results",fontsize=15)
这是输出
要创建一个直方图,其中四舍五入到2位小数的值定义了箱子,可以在这些值中间创建箱子边。例如
0.195
和0.205
处的箱子边缘将定义0.20
周围的箱子。您可以使用'np.arange(-0.005,1.01,0.01)'创建具有这些容器边缘的数组为了只在使用的位置设置记号标签,可以使用
ax.set_yticks()
。可以对所有y值进行舍入,并对y记号使用唯一的值如果不需要舍入,而需要截断,可以使用
bins=np.arange(0, 1.01, 0.01)
和ax.set_yticks(np.unique(np.round(y-0.005, 2)))
请注意,即使字体大小较小,记号标签也可能重叠
另一种方法是对舍入(或截断)的值使用
countplot
。然后,条间距均匀,不考虑空点:这由matplotlib处理:
您可能需要使用以下选项:
或者这个:
binwidth=0.01
:相关问题 更多 >
编程相关推荐