具有非标度y轴的箱线图

时间:2012-08-22 16:23:04

标签: python plot matplotlib boxplot outliers

我有一些我想要封存的数据。异常值(例如20,30)离大多数值太远(例如0.0002,0.0003),因此当我用matplotlib绘图时,我只能看到异常值。

无论如何要放大中位数周围的值,然后让y轴的其余部分不按比例显示并显示异常值吗?

EDIT 这是我在python中的代码。我想使用插入轴,如下所示,我有每个箱形图。我怎么能这么简单地做到这一点?从文档中的示例中可以看出有太多参数需要处理。

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)

2 个答案:

答案 0 :(得分:1)

您可以按照本页所述进行插入轴,大约向下1/2。

inset axes

答案 1 :(得分:1)

一个非常老的问题,但是我遇到这个问题是在寻找类似的东西。我通过添加sym =''(此选项可能7年前不存在!)解决了这个问题,它告诉boxplot不要显示传单(晶须以外的任何东西)。

因此,对于遇到此问题的其他人,您可以尝试将问题中的第3行更改为:

plt.boxplot(dataToPlot, sym='')
相关问题