简体   繁体   English

具有非标度y轴的箱线图

[英]boxplots with not-in-scale y-axis

I have some data I want to box plot. 我有一些数据我想要盒子图。 Outliers (eg 20, 30) are too far away from most values (eg 0.0002, 0.0003) and as a consequence I can only see outliers when I plot with matplotlib. 异常值(例如20,30)离大多数值太远(例如0.0002,0.0003),因此当我用matplotlib绘制时,我只能看到异常值。

Is there anyway to zoom in the values around the median and then let the rest of the y-axis not be in scale and display outliers too? 无论如何要放大中位数周围的值,然后让y轴的其余部分不按比例放大并显示异常值?

EDIT Here's my code in python. 编辑这是我在python中的代码。 I would like to use inset axes, as suggested below, for each box plot I have. 我想使用插入轴,如下所示,我有每个箱形图。 How can I do this in an easy way? 我怎么能这么简单地做到这一点? There seems to be way too many parameters to take care of from the examples in the documentation. 从文档中的示例中可以看出有太多参数需要处理。

plt.figure()
        ax = plt.subplot(111)
        plt.boxplot(dataToPlot)
        axins = zoomed_inset_axes(ax, 6, loc=1) # zoom = 6
# what follows is taken from example linked in the answer below. 
# I didn't get if the first argument is indeed the data this zoomed image refers to or not. 
        axins.imshow(dataToPlot[1], interpolation="nearest", origin="lower")
# here I only need the y-axis to be in [0,0.1], x-axis is no of use with vertical boxplots
        x1, x2, y1, y2 = -1.5, -0.9, 0.0, 0.1
        axins.set_xlim(x1, x2)
        axins.set_ylim(y1, y2)
        plt.xticks(visible=True)
        plt.yticks(visible=True)
        plt.savefig( 'somewhere.jpeg', bbox_inches=0)

You could do an inset axes as described on this page, about 1/2 way down. 您可以按照本页所述进行插入轴,大约向下1/2。

inset axes 插入轴

Very old question, but I came across this looking for something similar. 很老的问题,但我遇到了这个寻找类似的东西。 I solved this by adding sym='' (this option may have not existed 7 years ago!) which tells boxplot not to show fliers (anything past the whiskers). 我通过添加sym =''解决了这个问题(这个选项可能在7年前就不存在了!),它告诉boxplot不要显示传单(任何过去的胡须)。

So for anyone else who comes across this, you might try changing line 3 in the question to: 因此,对于遇到此问题的其他人,您可以尝试将问题中的第3行更改为:

plt.boxplot(dataToPlot, sym='')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM