本文整理汇总了Python中matplotlib.pyplot.errorbar方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.errorbar方法的具体用法?Python pyplot.errorbar怎么用?Python pyplot.errorbar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.errorbar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_abnormal_cumulative_return_with_errors
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def plot_abnormal_cumulative_return_with_errors(abnormal_volatility, abnormal_returns, events):
"""
Capturing volatility of abnormal returns
"""
pyplot.figure(figsize=FIGURE_SIZE)
pyplot.errorbar(
abnormal_returns.index,
abnormal_returns,
xerr=0,
yerr=abnormal_volatility,
label="events=%s" % events
)
pyplot.grid(b=None, which=u'major', axis=u'y')
pyplot.title("Abnormal Cumulative Return from Events with error")
pyplot.xlabel("Window Length (t)")
pyplot.ylabel("Cumulative Return (r)")
pyplot.legend()
pyplot.show()
示例2: plot_gap
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def plot_gap(cls, algorithm, dname):
if dname is None:
return
if not os.path.exists(dname):
os.mkdir(dname)
plt.figure()
plt.title(algorithm.estimator.__class__.__name__)
plt.xlabel("Number of clusters")
plt.ylabel("Gap statistic")
plt.plot(range(algorithm.results['min_nc'], algorithm.results['max_nc'] + 1),
algorithm.results['gap'], 'o-', color='dodgerblue')
plt.errorbar(range(algorithm.results['min_nc'], algorithm.results['max_nc'] + 1),
algorithm.results['gap'], algorithm.results['gap_sk'], capsize=3)
plt.axvline(x=algorithm.results['gap_nc'], ls='--', C='gray', zorder=0)
plt.savefig('%s/gap_%s.png' %
(dname, algorithm.estimator.__class__.__name__),
bbox_inches='tight', dpi=75)
plt.close()
示例3: quad_fit
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def quad_fit(x, y, yerr, name, unit):
""" Fit a qudratic to the SNR to make a lookup error table """
print("performing quad fit")
qfit = np.polyfit(x, y, deg=2, w = 1 / yerr)
print(qfit)
plt.figure()
#plt.scatter(x, y)
plt.errorbar(x, y, yerr=yerr, fmt='.', c='k')
xvals = np.linspace(min(x), max(x), 100)
print(xvals)
yvals = qfit[2] + qfit[1]*xvals + qfit[0]*xvals**2
print(yvals)
plt.plot(xvals, yvals, color='r', lw=2)
plt.xlabel("%s" %snr_label, fontsize=16)
plt.ylabel(r"$\sigma %s \mathrm{(%s)}$" %(name,unit), fontsize=16)
plt.show()
示例4: example1
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def example1():
"""
Compute the GRADEV of a white phase noise. Compares two different
scenarios. 1) The original data and 2) ADEV estimate with gap robust ADEV.
"""
N = 1000
f = 1
y = np.random.randn(1,N)[0,:]
x = [xx for xx in np.linspace(1,len(y),len(y))]
x_ax, y_ax, (err_l, err_h), ns = allan.gradev(y,data_type='phase',rate=f,taus=x)
plt.errorbar(x_ax, y_ax,yerr=[err_l,err_h],label='GRADEV, no gaps')
y[int(np.floor(0.4*N)):int(np.floor(0.6*N))] = np.NaN # Simulate missing data
x_ax, y_ax, (err_l, err_h) , ns = allan.gradev(y,data_type='phase',rate=f,taus=x)
plt.errorbar(x_ax, y_ax,yerr=[err_l,err_h], label='GRADEV, with gaps')
plt.xscale('log')
plt.yscale('log')
plt.grid()
plt.legend()
plt.xlabel('Tau / s')
plt.ylabel('Overlapping Allan deviation')
plt.show()
示例5: test_errorbar_shape
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def test_errorbar_shape():
fig = plt.figure()
ax = fig.gca()
x = np.arange(0.1, 4, 0.5)
y = np.exp(-x)
yerr1 = 0.1 + 0.2*np.sqrt(x)
yerr = np.vstack((yerr1, 2*yerr1)).T
xerr = 0.1 + yerr
with pytest.raises(ValueError):
ax.errorbar(x, y, yerr=yerr, fmt='o')
with pytest.raises(ValueError):
ax.errorbar(x, y, xerr=xerr, fmt='o')
with pytest.raises(ValueError):
ax.errorbar(x, y, yerr=yerr, xerr=xerr, fmt='o')
示例6: errorbars
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def errorbars(x, y, err,
save_path='',
title='',
xlabel='',
ylabel='',
label=''):
if label:
plt.errorbar(x, y, yerr=err, label=label, fmt='-o')
plt.legend(loc='best')
else:
plt.errorbar(x, y, yerr=err, fmt='-o')
plt.title(title)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
if save_path:
plt.savefig(save_path)
plt.close()
示例7: plot_metric
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def plot_metric(metric, start_x=0, color=None, label=None, zorder=None):
import matplotlib.pyplot as plt
metric_mean = np.mean(metric, axis=0)
metric_se = np.std(metric, axis=0) / np.sqrt(len(metric))
kwargs = {}
if color:
kwargs['color'] = color
if zorder:
kwargs['zorder'] = zorder
plt.errorbar(np.arange(len(metric_mean)) + start_x,
metric_mean, yerr=metric_se, linewidth=2,
label=label, **kwargs)
# metric_std = np.std(metric, axis=0)
# plt.plot(np.arange(len(metric_mean)) + start_x, metric_mean,
# linewidth=2, color=color, label=label)
# plt.fill_between(np.arange(len(metric_mean)) + start_x,
# metric_mean - metric_std, metric_mean + metric_std,
# color=color, alpha=0.5)
示例8: update_errorbar
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def update_errorbar(errobj, x, y, y_error):
# from http://stackoverflow.com/questions/25210723/matplotlib-set-data-for-errorbar-plot
ln, (erry_top, erry_bot), (barsy,) = errobj
ln.set_xdata(x)
ln.set_ydata(y)
x_base = x
y_base = y
yerr_top = y_base + y_error
yerr_bot = y_base - y_error
erry_top.set_xdata(x_base)
erry_bot.set_xdata(x_base)
erry_top.set_ydata(yerr_top)
erry_bot.set_ydata(yerr_bot)
new_segments_y = [np.array([[x, yt], [x,yb]]) for x, yt, yb in zip(x_base, yerr_top, yerr_bot)]
barsy.set_segments(new_segments_y)
示例9: calib_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def calib_plot(fu_time, n_bins, pred_surv, time, dead, color, label, error_bars=0,alpha=1., markersize=1., markertype='o'):
cuts = np.concatenate((np.array([-1e6]),np.percentile(pred_surv, np.arange(100/n_bins,100,100/n_bins)),np.array([1e6])))
bin = pd.cut(pred_surv,cuts,labels=False)
kmf = KaplanMeierFitter()
est = []
ci_upper = []
ci_lower = []
mean_pred_surv = []
for which_bin in range(max(bin)+1):
kmf.fit(time[bin==which_bin], event_observed=dead[bin==which_bin])
est.append(np.interp(fu_time, kmf.survival_function_.index.values, kmf.survival_function_.KM_estimate))
ci_upper.append(np.interp(fu_time, kmf.survival_function_.index.values, kmf.confidence_interval_.loc[:,'KM_estimate_upper_0.95']))
ci_lower.append(np.interp(fu_time, kmf.survival_function_.index.values, kmf.confidence_interval_.loc[:,'KM_estimate_lower_0.95']))
mean_pred_surv.append(np.mean(pred_surv[bin==which_bin]))
est = np.array(est)
ci_upper = np.array(ci_upper)
ci_lower = np.array(ci_lower)
if error_bars:
plt.errorbar(mean_pred_surv, est, yerr = np.transpose(np.column_stack((est-ci_lower,ci_upper-est))), fmt='o',c=color,label=label)
else:
plt.plot(mean_pred_surv, est, markertype, c=color,label=label, alpha=alpha, markersize=markersize)
return (mean_pred_surv, est)
示例10: plot_lds_results
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def plot_lds_results(X, z_mean, z_std, pis):
# Plot the true and inferred states
plt.figure()
ax1 = plt.subplot(311)
plt.errorbar(z_mean[:,0], color="r", yerr=z_std[:,0])
plt.errorbar(z_mean[:,1], ls="--", color="r", yerr=z_std[:,1])
ax1.set_title("True and inferred latent states")
ax2 = plt.subplot(312)
plt.imshow(X.T, interpolation="none", vmin=0, vmax=1, cmap="Blues")
ax2.set_title("Observed counts")
ax4 = plt.subplot(313)
N_samples = pis.shape[0]
plt.imshow(pis[N_samples//2:,...].mean(0).T, interpolation="none", vmin=0, vmax=1, cmap="Blues")
ax4.set_title("Mean inferred probabilities")
plt.show()
示例11: plot_graph
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def plot_graph(network, err=None, start_x=1, color="black", ecolor="red", title="Title", x_label="X", y_label="Y", ylim=None):
start_x = int(start_x)
num_nodes = network.shape[0]
nodes_axis = range(start_x, num_nodes + start_x)
plt.axhline(0, color='black')
if err is not None:
plt.errorbar(nodes_axis, network, err, color="black", ecolor="red")
else:
plt.plot(nodes_axis, network, color="black")
if ylim:
axes = plt.gca()
axes.set_ylim(ylim)
plt.title(title, fontsize=18)
plt.xlabel(x_label, fontsize=16)
plt.ylabel(y_label, fontsize=16)
示例12: matplotlib
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def matplotlib(self, showtitle=True, show=False, **kwargs):
import matplotlib.pyplot as pyplot
_xerrs = [self.xerrorslow, self.xerrorshigh]
_yerrs = [self.yerrorslow, self.yerrorshigh]
_xlabel = _decode(self.xlabel if self.xlabel is not None else "")
_ylabel = _decode(self.ylabel if self.ylabel is not None else "")
pyplot.errorbar(self.xvalues, self.yvalues, xerr=_xerrs, yerr=_yerrs, **kwargs)
pyplot.xlabel(_xlabel)
pyplot.ylabel(_ylabel)
if showtitle:
_title = _decode(self.title)
pyplot.title(_title)
if show:
pyplot.show()
示例13: plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def plot(self, show=True, fpath=None):
f = plt.figure()
for d in self.data:
fmt = (self.color_to_str.get(d['color'], '') +
self.line_type_to_str.get(d['line_type'], ''))
plt.errorbar(d['xs'],
d['ys'],
yerr=d['err'],
label=d['label'],
fmt=fmt)
if self.title is not None:
plt.title(self.title)
if self.xlabel is not None:
plt.xlabel(self.xlabel)
if self.ylabel is not None:
plt.ylabel(self.ylabel)
if any([d['label'] is not None for d in self.data]):
plt.legend(loc='best')
if fpath is not None:
f.savefig(fpath, bbox_inches='tight')
if show:
plt.show()
return f
示例14: fit_plot_central_charge
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def fit_plot_central_charge(s_list, xi_list, filename):
"""Plot routine in order to determine the cental charge."""
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
def fitFunc(Xi, c, a):
return (c / 6) * np.log(Xi) + a
Xi = np.array(xi_list)
S = np.array(s_list)
LXi = np.log(Xi) # Logarithm of the correlation length xi
fitParams, fitCovariances = curve_fit(fitFunc, Xi, S)
# Plot fitting parameter and covariances
print('c =', fitParams[0], 'a =', fitParams[1])
print('Covariance Matrix', fitCovariances)
# plot the data as blue circles
plt.errorbar(LXi,
S,
fmt='o',
c='blue',
ms=5.5,
markerfacecolor='white',
markeredgecolor='blue',
markeredgewidth=1.4)
# plot the fitted line
plt.plot(LXi,
fitFunc(Xi, fitParams[0], fitParams[1]),
linewidth=1.5,
c='black',
label='fit c={c:.2f}'.format(c=fitParams[0]))
plt.xlabel(r'$\log{\,}\xi_{\chi}$', fontsize=16)
plt.ylabel(r'$S$', fontsize=16)
plt.legend(loc='lower right', borderaxespad=0., fancybox=True, shadow=True, fontsize=16)
plt.savefig(filename)
示例15: plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import errorbar [as 别名]
def plot(base, regex, criterion, retrieve_list):
keys = map(int_or_float, [a.split('/')[-1] for a in glob.glob(base + '*')])
means, std_devs = {}, {}
for i, key in enumerate(keys):
pattern = base + str(key) + regex
answer = find_best(pattern, criterion, retrieve_list)
if answer[0] is not None:
means[key], std_devs[key] = answer
plot_keys = sorted(means.keys())
means = np.asarray([means[key] for key in plot_keys])
std_devs = np.asarray([std_devs[key] for key in plot_keys])
(_, caps, _) = plt.errorbar(plot_keys, means, yerr=1.96*std_devs,
marker='o', markersize=5, capsize=5)
for cap in caps:
cap.set_markeredgewidth(1)