箱图中的自动(晶须敏感)ylim [英] Automatic (whisker-sensitive) ylim in boxplots
问题描述
在绘制带有熊猫的数据框的列时,例如
When plotting columns of a dataframe with pandas, e.g.
df.boxplot()
yaxis
的自动调整会导致绘图中大量未使用的空间.我想知道这是否是因为数据框的点超过了箱线图的晶须(但由于某些原因,未显示异常值).如果是这种情况,哪种自动调整ylim
的好方法是什么,以便在绘图中没有太多的空白空间?
the automatic adjustment of the yaxis
can lead to a large amount of unused space in the plot. I wonder if this is because the dataframe has points that exceed the boxplot whiskers (but for some reason the outliers aren't displayed). If that is the case, what would be a good way to automatically adjust ylim
so that there isn't so much empty space in the plot?
推荐答案
我认为,seaborn风格和matplotlib绘制箱形图的方式的结合在这里隐藏了您的异常值.
I think a combination of the seaborn style and the way matplotlib draws boxplots is hiding your outliers here.
如果我生成一些偏斜的数据
If I generate some skewed data
import seaborn as sns
import pandas as pd
import numpy as np
x = pd.DataFrame(np.random.lognormal(size=(100, 6)),
columns=list("abcdef"))
然后在数据框上使用boxplot
方法,我看到类似的内容
And then use the boxplot
method on the dataframe, I see something similar
x.boxplot()
但是,如果更改用于绘制异常值的符号,则会得到
But if you change the symbol used to plot outliers, you get
x.boxplot(sym="k.")
或者,您可以使用seaborn的boxplot
函数,该函数执行相同的操作,但具有一些美观的外观:
Alternatively, you can use the seaborn boxplot
function, which does the same thing but with some nice aesthetics:
sns.boxplot(x)
这篇关于箱图中的自动(晶须敏感)ylim的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!