【问题标题】:boxplots with not-in-scale y-axis具有非比例 y 轴的箱线图
【发布时间】:2012-08-18 03:07:04
【问题描述】:

我有一些数据要绘制箱线图。异常值(例如 20、30)离大多数值(例如 0.0002、0.0003)太远,因此我只能在使用 matplotlib 绘图时看到异常值。

是否有办法放大中位数周围的值,然后让 y 轴的其余部分不按比例显示异常值?

编辑 这是我在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)

【问题讨论】:

    标签: python plot matplotlib boxplot outliers


    【解决方案1】:

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

    inset axes

    【讨论】:

    • 对不起,误读了这个问题。插入轴听起来更像你想要的吗?
    • 是那个还是对数缩放?
    • 谢谢!插入轴听起来很有趣。不过,该页面中的示例并不太详细。我在同一张图上绘制了多个箱线图。我究竟如何为每个箱形图绘制这样的插入轴?
    • 我用您建议的功能的更多详细信息编辑了我的问题。
    • 我认为您可以将插入轴附加到任何 plt 对象。因此,如果您为每个数据集创建了多个 plt 对象,则可以为每个对象附加一个插入轴。可能只想为每个数据集做子图,然后在每个数据集上做一个插入轴。目前没有方便的 matplotlib 进行测试。 . .
    【解决方案2】:

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

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

    plt.boxplot(dataToPlot, sym='')
    

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多