Skip to content

Instantly share code, notes, and snippets.

@vgauthier
Created December 20, 2012 08:04
Show Gist options
  • Save vgauthier/4343692 to your computer and use it in GitHub Desktop.
Save vgauthier/4343692 to your computer and use it in GitHub Desktop.
Python: Function to plot an nice error bar with Matplotlib
def errorfill(x, y, yerr, color=None, alpha_fill=0.3, ax=None):
# Plot the standart error bar stolen from http://tonysyu.github.com/plotting-error-bars.html
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment