Error Bar Plot Matplotlib
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 http://stackoverflow.com/questions/18498742/how-do-you-make-an-errorbar-plot-in-matplotlib-using-linestyle-none-in-rcparams company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 https://tonysyu.github.io/plotting-error-bars.html million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How do you make an errorbar plot in matplotlib using linestyle=None in rcParams? up vote 5 down vote favorite 3 error bar When plotting errorbar plots, matplotlib is not following the rcParams of no linestyle. Instead, it's plotting all of the points connected with a line. Here's a minimum working example: import matplotlib.pyplot as plt lines = {'linestyle': 'None'} plt.rc('lines', **lines) plt.errorbar((0, 1), (1, 0), yerr=(0.1, 0.1), marker='o') plt.savefig('test.pdf') plt.delaxes() Is the only solution to explicitly set linestyle='None' when calling pyplot.errorbar()? python matplotlib share|improve this question edited Aug 28 '13 at 21:44 jabaldonedo 9,97223351 asked matplotlib error bar Aug 28 '13 at 21:42 drs 1,79021636 add a comment| 1 Answer 1 active oldest votes up vote 19 down vote accepted This is a "bug" in older versions of matplotlib (and has been fixed for the 1.4 series). The issue is that in Axes.errorbar there is a default value of '-' for fmt, which is then passed to the call to plot which is used to draw the markers and line. Because a format string is passed into plot in never looks at the default value in rcparams. You can also pass in fmt = '' eb = plt.errorbar(x, y, yerr=.1, fmt='', color='b') which will cause the rcParam['lines.linestlye'] value to be respected. I have submitted a PRto implement this. Another work around for this is to make the errorbar in two steps: l0, = plt.plot(x,y, marker='o', color='b') eb = plt.errorbar(x, y, yerr=.1, fmt=None, color='b') This is an annoying design decision, but changing it would be a major api break. Please open an issue on github about this. errorbar doc. As a side note, it looks like the call signature was last changed in 2007, and that was to make errorbars not default to blue. share|improve this answer edited May 25 '15 at 21:33 answered Aug 28 '13 at 22:12 tacaswell 36.4k37794 Thanks, I've ope
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