Upper/lower limits with matplotlib

后端 未结 1 421
情书的邮戳
情书的邮戳 2021-02-14 07:26

I want to plot some data points with errorbars. Some of these data points have only upper or lower limit, instead of error bars.

So I was trying to use indices to differ

相关标签:
1条回答
  • 2021-02-14 07:56

    This is actually one of the things that tends to annoy me about errorbar: it's very finicky about the shape and dimensionality of inputs.

    What I'm assuming is that you want "error bars", but want their locations to be set by absolute upper and lower bounds, rather than by a symmetric "error" value.

    What errorbar does is zip together (with safezip) your y array and yerr[0] for the lower bound (yerr[1] for upper). So your y and yerr[0] (and [1]) should be arrays with the same size, shape and number of dimensions. yerr itself doesn't need to be an array at all.

    The first code that you have will work if x, y, ymin, and ymax are all one-dimensional arrays, which is what they should be. It sounds like your y is not.

    However, it's important to note that since errorbar yerr are error amounts, and not absolute limits, you need to add and subtract your y from your actual lower and upper limits.

    For example:

    x = array([1,2,3,4])
    y = array([1,2,3,4])  
    ymin = array([0,1,2,3])
    ymax = array([3,4,5,6])
    ytop = ymax-y
    ybot = y-ymin
    
    # This works
    errorbar( x, y, yerr=(ybot, ytop) )
    

    Let me know if I'm misinterpreting anything. It would be good if you could post some example data in the form that you're using.

    0 讨论(0)
提交回复
热议问题