Plotting Error Bars Python
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn errorbar() got multiple values for keyword argument 'yerr' more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags
Plt.errorbar Documentation
Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like
Seaborn Error Bars
you, helping each other. Join them; it only takes a minute: Sign up Python Pylab scatter plot error bars (the error on each point is unique) up vote 4 down vote favorite I am attempting a scatter plot http://matplotlib.org/1.2.1/examples/pylab_examples/errorbar_demo.html of 2 arrays for which I have a third array containing the absolute error (error in y direction) on each point. I want the error bars to between (point a - error on a) and (point a + error on a). Is there a way of achieving this with pylab and if not any ideas on how else I could do it? Thanks in advance python matplotlib share|improve this question asked Mar 12 '14 at 21:46 http://stackoverflow.com/questions/22364565/python-pylab-scatter-plot-error-bars-the-error-on-each-point-is-unique user3412782 31116 add a comment| 1 Answer 1 active oldest votes up vote 5 down vote accepted >>> import matplotlib.pyplot as plt >>> a = [1,3,5,7] >>> b = [11,-2,4,19] >>> plt.pyplot.scatter(a,b) >>> plt.scatter(a,b)
you would just call matplotlib's errorbar function: import numpy https://tonysyu.github.io/plotting-error-bars.html as np import matplotlib.pyplot as plt x = np.linspace(0, 2 * np.pi) y_sin = np.sin(x) y_cos = np.cos(x) plt.errorbar(x, y_sin, 0.2) plt.errorbar(x, y_cos, 0.2) plt.show() which produces the following plot: The numerous error bars make the plot really noisy, and, in my opinion, they're really distracting. Instead, error bars you could use matplotlib's fillbetween to denote the error as a region in the plot. In the following, I try to imitate errorbar's interface (minus many additional key-word arguments): def errorfill(x, y, yerr, color=None, alpha_fill=0.3, ax=None): ax = ax if ax is not None else plt.gca() if color error bars python is None: color = ax._get_lines.color_cycle.next() if np.isscalar(yerr) or len(yerr) == len(y): ymin = y - yerr ymax = y + yerr elif len(yerr) == 2: ymin, ymax = yerr ax.plot(x, y, color=color) ax.fill_between(x, ymax, ymin, color=color, alpha=alpha_fill) Continuing with the data and imports from the first code block, you can use the errorfill function as follows: errorfill(x, y_sin, 0.2) errorfill(x, y_cos, 0.2) plt.show() which gives: With the fill method, you lose information about the direction of the error (especially if you have errors in both x and y), but for most use cases, this works pretty well. Comments Please enable JavaScript to view the comments powered by Disqus. comments powered by Disqus Software developer, engineer, and all-around good guy in Austin, TX, USA. Links github linkedin Tags © 2016 Tony S. Yu · Powered by pelican-bootstrap3, Pelican, Bootstrap Back to top