我有一个 DataFrame(称为 result_df
)并想用箱线图绘制一列。
但某些异常值破坏了可视化效果。如何防止绘制异常值?
我使用的代码:
fig, ax = pl.subplots()
fig.set_size_inches(18.5,10.5)
result_df.boxplot(ax=ax)
pl.show()
最佳答案
重要提示:我没有给予足够的重视,显然这种情况经常发生,而且我错过了它是 pandas
特定的。但是,从我看到的问题来看,它基本上是用于在后台绘图的 matplotlib,因此它仍然可以工作。对不起,我没能更加小心。
幸运的是,有这样的事情。在manual在 results: 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/