如何在 python 中重新调整箱形图的 y 轴
How to rescale the y-axis of a boxplot in python
我在下面有一个箱线图(使用 seaborn),其中 "box" 部分太压扁了。如何更改沿 y 轴的比例以使箱线图更易于呈现(即 "box" 部分太压扁)但仍保留图中的所有异常值?
非常感谢。
您可以在绘图后设置坐标轴:
import seaborn as sns
df = sns.load_dataset('iris')
a = sns.boxplot(y=df["sepal_length"])
a.set(ylim=(0,10))
此外,您可以尝试从 boxplot
中传递 showfliers = False
的图中删除异常值。
你可以在这里做两件事。
- 把情节做大
- 改变y轴的范围
由于您想保留离群值,因此重新缩放 y 轴可能不会那么有效。您没有提供任何数据或代码示例。所以我就加一个方法让你的身材变大
# this script makes the figure bigger and rescale the y-axis
ax = plt.figure(figsize=(20,15))
ax = sns.boxplot(x="day", y="total_bill", data=tips)
ax.set_ylim(0,100)
我在下面有一个箱线图(使用 seaborn),其中 "box" 部分太压扁了。如何更改沿 y 轴的比例以使箱线图更易于呈现(即 "box" 部分太压扁)但仍保留图中的所有异常值?
非常感谢。
您可以在绘图后设置坐标轴:
import seaborn as sns
df = sns.load_dataset('iris')
a = sns.boxplot(y=df["sepal_length"])
a.set(ylim=(0,10))
此外,您可以尝试从 boxplot
中传递 showfliers = False
的图中删除异常值。
你可以在这里做两件事。
- 把情节做大
- 改变y轴的范围
由于您想保留离群值,因此重新缩放 y 轴可能不会那么有效。您没有提供任何数据或代码示例。所以我就加一个方法让你的身材变大
# this script makes the figure bigger and rescale the y-axis
ax = plt.figure(figsize=(20,15))
ax = sns.boxplot(x="day", y="total_bill", data=tips)
ax.set_ylim(0,100)