Created
December 20, 2012 08:04
-
-
Save vgauthier/4343692 to your computer and use it in GitHub Desktop.
Python: Function to plot an nice error bar with Matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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