Permalink
Browse files

Port part of errorfill from Tony Yu's mpltools.

Specifically, the function `extrema_from_error_input` from

https://github.com/tonysyu/mpltools/blob/master/mpltools/special/errorfill.py#L54

is ported to matplotlib.mlab.
  • Loading branch information...
1 parent f6b7f28 commit d2998e67fb4f9b24cf2bc1551dcd66945431be8c @dmcdougall committed Jul 14, 2012
Showing with 19 additions and 0 deletions.
  1. +19 −0 lib/matplotlib/mlab.py
View
@@ -3182,3 +3182,22 @@ def quad2cubic(q0x, q0y, q1x, q1y, q2x, q2y):
c2x, c2y = c1x + 1./3. * (q2x - q0x), c1y + 1./3. * (q2y - q0y)
# c3x, c3y = q2x, q2y
return q0x, q0y, c1x, c1y, c2x, c2y, q2x, q2y
+
+def offset_line(x, xerr):
+ """
+ Offsets an array *x* by +/- an error and returns a tuple (x - err, x + err).
+
+ The error term can be:
+
+ o A scalar. In this case, the returned tuple is obvious.
+ o A vector of the same length as *x*. The quantities x +/- err are computed
+ component-wise.
+ o A tuple of length 2. In this case, xerr[0] is the error below *x* and
+ xerr[1] is error above *x*.
+ """
+ if np.isscalar(xerr) or len(xerr) == len(x):
+ xmin = x - xerr
+ xmax = x + xerr
+ elif len(xerr) == 2:
+ xmin, xmax = x - xerr[0], x + xerr[1]
+ return xmin, xmax

0 comments on commit d2998e6

Please sign in to comment.