在Python中更改Boxplot Y轴的范围

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

如何更改 y 轴值以显示完整位数?

import seaborn as sns
sns.boxplot (x="waterfront", y="price", data=df)

我想要显示完整的数字范围(如屏幕截图“目标”中),但我创建的箱线图显示了带注释的数字(如屏幕截图“当前”中)。

目标:

Target scale

当前:

Current scale

python seaborn boxplot
2个回答
0
投票

从这里查看答案:Seaborn / Matplotlib:如何在因子图 y 轴中抑制科学记数法

这是您需要的代码:

import seaborn as sns
import matplotlib.pyplot as plt

sns.boxplot (x="waterfront", y="price", data=df)
plt.ticklabel_format(style='plain', axis='y',useOffset=False)

example picture


0
投票

您需要复制此代码: 将seaborn导入为sns 将 matplotlib.pyplot 导入为 plt

自定义调色板 = ['#2477BF', '#F26101']

定义传单属性以更改标记样式和颜色

flierprops = dict(marker='D',markerfacecolor=['grey','#2477BF'],markersize=4,linestyle='none')

sns.boxplot(x='海滨', y='价格', 数据=df, 调色板=custom_palette, flierprops=flierprops)

设置 y 轴格式以避免科学计数法

plt.ticklabel_format(style='plain', axis='y', useOffset=True)

显示情节

plt.show()

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