python - 如何防止在 pandas 的箱线图中绘制异常值

标签 python pandas

我有一个 DataFrame(称为 result_df)并想用箱线图绘制一列。

但某些异常值破坏了可视化效果。如何防止绘制异常值?

我使用的代码:

fig, ax = pl.subplots()
fig.set_size_inches(18.5,10.5)
result_df.boxplot(ax=ax)
pl.show()

最佳答案

重要提示:我没有给予足够的重视,显然这种情况经常发生,而且我错过了它是 pandas 特定的。但是,从我看到的问题来看,它基本上是用于在后台绘图的 matplotlib,因此它仍然可以工作。对不起,我没能更加小心。

幸运的是,有这样的事情。在manualresults: dict title 下,它指向页面底部:

fliers: points representing data that extend beyond the whiskers (outliers).

设置 showfliers=False 希望对您有所帮助。

不过我不得不提的是,我发现他们将离群值缩短为传单真的很奇怪。如果那没有帮助 manual提供第二种解决方案:

sym : str or None, default = None

The default symbol for flier points. Enter an empty string (‘’) if you don’t want to show fliers. If None, then the fliers default to ‘b+’ If you want more control use the flierprops kwarg.

关于python - 如何防止在 pandas 的箱线图中绘制异常值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28725763/

相关文章:

python - 有没有办法使用 pandas 中的范围来选择一系列元素?

python-3.x - 加速 Pandas 迭代

python - 如何找到 ndarray 中索引的值并将其转换为 pandas Dataframe?

python - 基于 Python 中另一行的范围中的行值

python - Keras plot_model 没有正确显示输入层

python - 使用 pymssql 将数据插入 SQL Server 表

python - 为列值创建二进制指示符变量

python - 没有除法运算符的除法

python - 如何检查列表是否存在于 Python 中

在字典列表中查找公共(public)键值对的pythonic方法