如何在使用 Seaborn 制作箱线图时将 x 标签值截断为两位小数?查看了 Seaborn 文档,但正在努力寻找解决方案。
答案 0 :(得分: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()
现在剧情不会乱了