Upper / lower limits with matplotlib

I want to build some data points with errors. Some of these data points have only upper or lower limits, not error columns.

So, I tried to use indexes to distinguish between points with errors and points with an upper / lower limit. However, when I try something like this:

errorbar(x[i], y[i], yerr = (ymin[i], ymax[i])) 

I get an error message:

 ValueError: In safezip, len(args[0])=1 but len(args[1])=2 

This seems like a discussion here , but I am not using pandas, and it would be very helpful for me to read some other words about it.

In any case, I tried to "flip" the error as follows:

 errorbar(x[i], y[i], yerr = [[ymin[i], ymax[i]]], uplims = True) 

But the final graph is not clear: it seems that the upper limit AND the error frames are built together, or the upper limit is displayed twice ...

The goal is to plot the upper / lower limits when the upper and lower error bars are not symmetrical, so I can choose the length of the strip in front of the arrow for the upper / lower limit.

+7
source share
1 answer

In fact, this is one of the things that annoys me with a mistake: it is very subtle in terms of the shape and dimension of the inputs.

I assume that you want error strings, but want their locations to be set with absolute upper and lower bounds, rather than the symmetric error value.

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

The first code you have will work if x, y, ymin and ymax are all one-dimensional arrays, which is what should be. It seems like you haven't.

However, it is important to note that since errorbar yerr is the number of errors, not the absolute limits, you need to add and subtract 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 misinterpret something. It would be nice if you could post some sample data in the form you use.

+6
source

All Articles