Error Bars In 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 more about hiring developers or seaborn error bars posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss plt.errorbar no line Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only
Errorbar() Got Multiple Values For Keyword Argument 'yerr'
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 of 2 arrays for which I have a third array containing http://matplotlib.org/examples/statistics/errorbar_demo_features.html 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 user3412782 31116 add a comment| 1 Answer 1 active oldest votes up vote 5 down vote http://stackoverflow.com/questions/22364565/python-pylab-scatter-plot-error-bars-the-error-on-each-point-is-unique 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)
Editor. Build charts in a breeze with our online editor. Real-time Support. Get instant chat support from our awesome engineering team. plotly Pricing PLOTCON NYC API Sign In SIGN https://plot.ly/python/continuous-error-bars/ UP + NEW PROJECT UPGRADE REQUEST DEMO Feed Pricing Make a Chart API Sign https://tonysyu.github.io/plotting-error-bars.html In SIGN UP + NEW PROJECT UPGRADE REQUEST DEMO Show Sidebar Hide Sidebar Help API Libraries Python Continuous Error Bars Fork on Github Navigation Download THIS Notebook! Back to Python Continuous Error Bars in Python Add continuous error bars to charts in Python with Plotly. plotly.js Python New to Plotly?¶Plotly's Python library is free and error bars open source! Get started by downloading the client and reading the primer. You can set up Plotly to work in online or offline mode, or in jupyter notebooks. We also have a quick-reference cheatsheet (new!) to help you get started! Basic Continuous Error Bars¶ In[]: import plotly.plotly as py from plotly.graph_objs import * x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] x_rev = x[::-1] errorbar no line # Line 1 y1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y1_upper = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11] y1_lower = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] y1_lower = y1_lower[::-1] # Line 2 y2 = [5, 2.5, 5, 7.5, 5, 2.5, 7.5, 4.5, 5.5, 5] y2_upper = [5.5, 3, 5.5, 8, 6, 3, 8, 5, 6, 5.5] y2_lower = [4.5, 2, 4.4, 7, 4, 2, 7, 4, 5, 4.75] y2_lower = y2_lower[::-1] # Line 3 y3 = [10, 8, 6, 4, 2, 0, 2, 4, 2, 0] y3_upper = [11, 9, 7, 5, 3, 1, 3, 5, 3, 1] y3_lower = [9, 7, 5, 3, 1, -.5, 1, 3, 1, -1] y3_lower = y3_lower[::-1] trace1 = Scatter( x=x+x_rev, y=y1_upper+y1_lower, fill='tozerox', fillcolor='rgba(0,100,80,0.2)', line=Line(color='transparent'), showlegend=False, name='Fair', ) trace2 = Scatter( x=x+x_rev, y=y2_upper+y2_lower, fill='tozerox', fillcolor='rgba(0,176,246,0.2)', line=Line(color='transparent'), name='Premium', showlegend=False, ) trace3 = Scatter( x=x+x_rev, y=y3_upper+y3_lower, fill='tozerox', fillcolor='rgba(231,107,243,0.2)', line=Line(color='transparent'), showlegend=False, name='Fair', ) trace4 = Scatter( x=x, y=y1, line=Line(color='rgb(0,100,80)'), mode='lines', name='Fair', ) trace5 = Scatter( x=x, y=y2, line=Line(color='rgb(0,176,246)'), mode='lines', name='Premium', ) trace6 = Scatter( x=x, y=y3, line=Line(color='rgb(231,107,243)'), mode='lines', name='Ideal', ) data = Data([trace1, trace2, trace3, trace4, trace5, trace6]) layout = Layout( paper_bgcolor='rgb(255,255,255)', plot_bgcolor='rgb(229,229,229)', xaxis=XAxis( gridcolor='rgb(255,255,255)', range=[1,10], showgrid=True, showli
you would just call matplotlib's errorbar function: import numpy 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, 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 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