使用 Seaborn 制作箱线图

问题描述 投票:0回答:1

如何在使用 Seaborn 制作箱线图时将 x-label 值截断到小数点后两位?查看了 Seaborn 文档,但正在努力寻找解决方案。

seaborn boxplot
1个回答
0
投票

你没有放任何代码,所以我假设你的问题是你的 x 轴由于标签重叠而看起来很乱,因为它们有最多 5 到 8 位的十进制值。

import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

fig,ax=plt.subplots()
x=np.random.rand(10)

print(x)
# x looks like this [0.35216856 0.22145935 0.17762394 0.50507439 0.40720805 0.61499182 0.77852992 0.27904485 0.82737696 0.86285094]
ax = sns.boxplot(x=x)
xlabel=np.round(x, 2) # there may be better methods to round a numpy array
ax.set_xticklabels(xlabel) # input can be a list or array
plt.show()

现在剧情不会乱了

© www.soinside.com 2019 - 2024. All rights reserved.