本文整理汇总了Python中matplotlib.pyplot.fill_between函数的典型用法代码示例。如果您正苦于以下问题:Python fill_between函数的具体用法?Python fill_between怎么用?Python fill_between使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fill_between函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plotOverlapMatrix
def plotOverlapMatrix(O):
"""Plots the probability of observing a sample from state i (row) in state j (column).
For convenience, the neigboring state cells are fringed in bold."""
max_prob = O.max()
fig = pl.figure(figsize=(K/2.,K/2.))
fig.add_subplot(111, frameon=False, xticks=[], yticks=[])
for i in range(K):
if i!=0:
pl.axvline(x=i, ls='-', lw=0.5, color='k', alpha=0.25)
pl.axhline(y=i, ls='-', lw=0.5, color='k', alpha=0.25)
for j in range(K):
if O[j,i] < 0.005:
ii = ''
else:
ii = ("%.2f" % O[j,i])[1:]
alf = O[j,i]/max_prob
pl.fill_between([i,i+1], [K-j,K-j], [K-(j+1),K-(j+1)], color='k', alpha=alf)
pl.annotate(ii, xy=(i,j), xytext=(i+0.5,K-(j+0.5)), size=8, textcoords='data', va='center', ha='center', color=('k' if alf < 0.5 else 'w'))
cx = sorted(2*range(K+1))
cy = sorted(2*range(K+1), reverse=True)
pl.plot(cx[2:-1], cy[1:-2], 'k-', lw=2.0)
pl.plot(numpy.array(cx[2:-3])+1, cy[1:-4], 'k-', lw=2.0)
pl.plot(cx[1:-2], numpy.array(cy[:-3])-1, 'k-', lw=2.0)
pl.plot(cx[1:-4], numpy.array(cy[:-5])-2, 'k-', lw=2.0)
pl.xlim(0, K)
pl.ylim(0, K)
pl.savefig('O_MBAR.pdf', bbox_inches='tight', pad_inches=0.0)
pl.close(fig)
return
示例2: plot_validation_curve
def plot_validation_curve(model, X, y, scorer, param_name, param_range=np.linspace(0.1, 1, 5), cv=None, n_jobs=5,
ylim=None, title="Xval. validation curve"):
''' Plot learning curve for model on data '''
df = pd.DataFrame()
df['param_range'] = param_range
train_scores, test_scores = validation_curve(model, X, y, param_name=param_name, param_range=param_range,
cv=cv, scoring=scorer, n_jobs=n_jobs)
df['train_mean'] = 1 - np.mean(train_scores, axis=1)
df['train_std'] = np.std(train_scores, axis=1)
df['test_mean'] = 1 - np.mean(test_scores, axis=1)
df['test_std'] = np.std(test_scores, axis=1)
plt.figure()
plt.title(title)
if ylim is not None:
plt.ylim(*ylim)
plt.xlabel("Parameter value")
plt.ylabel("Error (1-score)")
plt.grid()
plt.semilogx(param_range, df.train_mean, color="r", label="Training")
plt.fill_between(param_range, df.train_mean - df.train_std, df.train_mean + df.train_std, alpha=0.1, color="r")
plt.semilogx(param_range, df.test_mean, color="g", label="Test")
plt.fill_between(param_range, df.test_mean - df.test_std, df.test_mean + df.test_std, alpha=0.1, color="g")
plt.legend(loc="best")
plt.show()
return df, plt
示例3: _plot_scores
def _plot_scores(tuo_location_and_influence_score, marking_locations, no_of_bins_for_influence_score, smooth=True):
figure = plt.figure()
size = figure.get_size_inches()
figure.set_size_inches( (size[0]*2, size[1]*0.5) )
influence_scores = zip(*tuo_location_and_influence_score)[1]
no_of_influence_scores = len(influence_scores)
hist_influence_score, bin_edges_influence_score = np.histogram(influence_scores, no_of_bins_for_influence_score)
normed_hist_influence_score = map(lambda influence_score: (influence_score+0.)/no_of_influence_scores, hist_influence_score)
bin_edges_influence_score = list(bin_edges_influence_score)
normed_hist_influence_score = list(normed_hist_influence_score)
bin_edges_influence_score=[bin_edges_influence_score[0]]+bin_edges_influence_score+[bin_edges_influence_score[-1]]
normed_hist_influence_score=[0.0]+normed_hist_influence_score+[0.0]
x_bin_edges_influence_score, y_normed_hist_influence_score = bin_edges_influence_score[:-1], normed_hist_influence_score
if smooth: x_bin_edges_influence_score, y_normed_hist_influence_score = splineSmooth(x_bin_edges_influence_score, y_normed_hist_influence_score)
plt.plot(x_bin_edges_influence_score, y_normed_hist_influence_score, lw=1, color='#FF9E05')
plt.fill_between(x_bin_edges_influence_score, y_normed_hist_influence_score, color='#FF9E05', alpha=0.3)
mf_neighbor_location_to_influence_score = dict(tuo_location_and_influence_score)
for marking_location in marking_locations:
if marking_location in mf_neighbor_location_to_influence_score:
print marking_location, mf_neighbor_location_to_influence_score[marking_location]
# plt.scatter([mf_neighbor_location_to_influence_score[marking_location]], [0.0005], s=20, lw=0, color=GeneralMethods.getRandomColor(), alpha=1., label=marking_location)
plt.scatter([mf_neighbor_location_to_influence_score[marking_location]], [0.0005], s=20, lw=0, color='m', alpha=1., label=marking_location)
else: print marking_location
# plt.xlim(get_new_xlim(plt.xlim()))
# plt.legend()
(ticks, labels) = plt.yticks()
plt.yticks([ticks[-2]])
plt.ylim(ymin=0.0)
return ticks[-1]
示例4: plot_forecast
def plot_forecast(fc, data=None, test=None, loc='upper left'):
'''
Plots a forecast and its prediction intervals.
Args:
fc: Pandas Data Frame from converters.prediction_intervals,
or an R forecast object
data: the data for the forecast period as a Pandas Series, or None
if fc is an R forecast
test: optional data for the forecast period as a Pandas Series
loc: Default is 'upper left', since plots often go up and right.
For other values see matplotlib.pyplot.legend().
Output:
a plot of the series, the mean forecast, and the prediciton intervals,
and optionally, the data for the forecast period, if provided,
'''
fc, data, test = converters.to_forecast(fc, data, test)
plt.style.use('ggplot')
l = list(fc.columns)
lowers = l[1::2]
uppers = l[2::2]
tr_idx = converters.flatten_index(data.index)
fc_idx = converters.flatten_index(fc.index)
plt.plot(tr_idx, data, color='black')
plt.plot(fc_idx, fc[l[0]], color='blue')
for (k, (low, up)) in enumerate(zip(lowers, uppers), 1):
plt.fill_between(fc_idx, fc[low], fc[up], color='grey', alpha=0.5/k)
labels = ['data', 'forecast']
if test is not None:
n = min(len(fc.index), len(test))
plt.plot(fc_idx[:n], list(test[:n]), color='green')
labels.append('test')
plt.legend(labels, loc=loc)
plt.show()
示例5: plot_learning_curve
def plot_learning_curve(estimator, title, X, y, ylim=None, cv=None,
n_jobs=1, train_sizes=np.linspace(.1, 1.0, 5)):
"""
source: http://scikit-learn.org/stable/auto_examples/plot_learning_curve.html
Generate a simple plot of the test and traning learning curve.
Parameters
----------
estimator : object type that implements the "fit" and "predict" methods
An object of that type which is cloned for each validation.
title : string
Title for the chart.
X : array-like, shape (n_samples, n_features)
Training vector, where n_samples is the number of samples and
n_features is the number of features.
y : array-like, shape (n_samples) or (n_samples, n_features), optional
Target relative to X for classification or regression;
None for unsupervised learning.
ylim : tuple, shape (ymin, ymax), optional
Defines minimum and maximum yvalues plotted.
cv : integer, cross-validation generator, optional
If an integer is passed, it is the number of folds (defaults to 3).
Specific cross-validation objects can be passed, see
sklearn.cross_validation module for the list of possible objects
n_jobs : integer, optional
Number of jobs to run in parallel (default 1).
"""
plt.figure()
plt.title(title)
if ylim is not None:
plt.ylim(*ylim)
plt.xlabel("Training examples")
plt.ylabel("Score")
train_sizes, train_scores, test_scores = learning_curve(
estimator, X, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes)
train_scores_mean = np.mean(train_scores, axis=1)
train_scores_std = np.std(train_scores, axis=1)
test_scores_mean = np.mean(test_scores, axis=1)
test_scores_std = np.std(test_scores, axis=1)
plt.grid()
plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
train_scores_mean + train_scores_std, alpha=0.1,
color="r")
plt.fill_between(train_sizes, test_scores_mean - test_scores_std,
test_scores_mean + test_scores_std, alpha=0.1, color="g")
plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
label="Training score")
plt.plot(train_sizes, test_scores_mean, 'o-', color="g",
label="Cross-validation score")
plt.legend(loc="best")
return plt
示例6: plot_layer
def plot_layer(self, layer):
layer = {k: v for k, v in layer.items() if k in self.VALID_AES}
layer.update(self.manual_aes)
if 'x' in layer:
x = layer.pop('x')
if 'y' in layer:
y = layer.pop('y')
if 'se' in layer:
se = layer.pop('se')
else:
se = None
if 'span' in layer:
span = layer.pop('span')
else:
span = 2/3.
if 'method' in layer:
method = layer.pop('method')
else:
method = None
if method == "lm":
y, y1, y2 = smoothers.lm(x, y)
elif method == "ma":
y, y1, y2 = smoothers.mavg(x, y)
else:
y, y1, y2 = smoothers.lowess(x, y)
idx = np.argsort(x)
x = np.array(x)[idx]
y = np.array(y)[idx]
y1 = np.array(y1)[idx]
y2 = np.array(y2)[idx]
plt.plot(x, y, **layer)
if se==True:
plt.fill_between(x, y1, y2, alpha=0.2, color="grey")
示例7: ModelComplexity
def ModelComplexity(X, y):
""" Calculates the performance of the model as model complexity increases.
The learning and testing errors rates are then plotted. """
# Create 10 cross-validation sets for training and testing
cv = ShuffleSplit(X.shape[0], n_iter = 10, test_size = 0.2, random_state = 0)
# Calculate the training and testing scores
#alpha_range = np.logspace(0.1, 1,num = 10, base = 0.1)
alpha_range = np.arange(0.1, 1, 0.1)
train_scores, test_scores = curves.validation_curve(Ridge(), X, y, \
param_name = "alpha", param_range = alpha_range, cv = cv, scoring = 'r2')
# Find the mean and standard deviation for smoothing
train_mean = np.mean(train_scores, axis=1)
train_std = np.std(train_scores, axis=1)
test_mean = np.mean(test_scores, axis=1)
test_std = np.std(test_scores, axis=1)
# Plot the validation curve
pl.figure(3)
pl.title('LinearRegression Complexity Performance')
pl.plot(alpha_range, train_mean, 'o-', color = 'r', label = 'Training Score')
pl.plot(alpha_range,test_mean, 'o-', color = 'g', label = 'Validation Score')
pl.fill_between(alpha_range, train_mean - train_std, \
train_mean + train_std, alpha = 0.15, color = 'r')
pl.fill_between(alpha_range, test_mean - test_std, \
test_mean + test_std, alpha = 0.15, color = 'g')
# Visual aesthetics
pl.legend(loc = 'lower right')
pl.xlabel('alpha_range')
pl.ylabel('Score')
pl.ylim([0.5000,1.0000])
pl.show()
示例8: plot_noisy_means
def plot_noisy_means(graph_title, means, bands, series, xvals=None, xlabel=None, ylabel=None, subtitle=None, data=None, filename='results.pdf'):
colors = ['blue','red','green', 'black', 'orange', 'purple', 'brown', 'yellow'] # max 8 lines
assert(means.shape == bands.shape)
assert(xvals is None or xvals.shape[0] == means.shape[1])
assert(means.shape[0] <= len(colors))
if xvals is None:
xvals = np.arange(means.shape[0])
ax = plt.axes([.1,.1,.8,.7])
plt.ticklabel_format(axis='y', style='plain', useOffset=False)
for i,mean in enumerate(means):
plt.plot(xvals, mean, label=series[i], color=colors[i])
plt.fill_between(xvals, mean + bands[i], mean - bands[i], facecolor=colors[i], alpha=0.2)
if xlabel is not None:
plt.xlabel(xlabel)
if ylabel is not None:
plt.ylabel(ylabel)
if subtitle is not None:
plt.figtext(.40,.9, graph_title, fontsize=18, ha='center')
plt.figtext(.40,.85, subtitle, fontsize=10, ha='center')
else:
plt.title('{0}'.format(graph_title))
# Shink current axis by 20%
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
# Put a legend to the right of the current axis
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), fontsize=12)
plt.savefig(filename)
plt.clf()
示例9: run_test
def run_test():
#x = np.array([0.0,.1,.2,.4,.75,.9,1.])
#x = np.array([0.0,0.1,0.2,0.3,0.4,0.5,0.7,0.8,0.9,0.95,1.0,0.6])
#x = np.linspace(0,1,10)
x = np.array([0, 0.2, 0.4, 0.6, 0.8, 1.0])
y = np.array([func(_x) for _x in x])
xp = np.linspace(0,1,100)
yp = func(xp)
krig = Kriging1D(x,y)
rbf = Rbf(x,y)
xk = np.linspace(0,1,100)
yk = np.zeros(len(xk))
yr = np.zeros(len(xk))
dk = np.zeros(len(xk))
for i,xx in enumerate(xk):
yk[i],dk[i] = krig(xx)
yr[i] = rbf(xx)
print sum(dk)
plt.figure(1)
plt.title('Kriging test')
plt.hold(True)
plt.plot(x,y,'rs')
plt.plot(xp,yp,'b-')
plt.plot(xk,yk,'r-')
#plt.plot(xk,yr,'g-')
plt.fill_between(xk,yk+0.5*dk,yk-0.5*dk,color='#dddddd')
plt.grid(True)
plt.axis([0,1,-10,20])
plt.legend(['sample point','exact function','kriging'],'upper left')
#plt.legend(['sample point','exact function','kriging','rbf'],'upper left')
plt.show()
示例10: plot_prior_1D
def plot_prior_1D(Xtest, test_cov, Ytest=None):
# Manipulate X for plotting
X = np.hstack(Xtest)
# Set prior mean function
mean = np.zeros(Xtest.shape)
s = np.sqrt(np.diag(test_cov))
mean = np.reshape(mean, (-1,))
# Plot true function, mean function and uncertainty
ax1 = plt.subplot(211)
plt.xlim(min(X), max(X))
plt.ylim(min(mean-(2*s)-(s/2)), max(mean+(2*s)+(s/2)))
if Ytest is not None:
plt.plot(X, Ytest, 'b-', label='Y')
plt.plot(X, mean, 'r--', lw=2, label='mean')
plt.fill_between(X, mean-(2*s), mean+(2*s), color='#87cefa')
plt.legend()
# Plot draws from prior
mean = mean.reshape(X.shape[0],1)
f = mean + np.dot(test_cov, np.random.normal(size=(X.shape[0],10)))
ax2 = plt.subplot(212, sharex=ax1)
plt.plot(X, f)
plt.title('Ten samples')
plt.tight_layout()
plt.show()
示例11: plot_posterior_1D
def plot_posterior_1D(Xtest, Xtrain, Ytrain, p_mean, p_sd, cov_post, Ytest=None):
# Manipulate data for plotting
mean_f = p_mean.flat
p_sd = np.reshape(p_sd, (-1,))
Xtest = np.hstack(Xtest)
# Plot true function, predicted mean and uncertainty (2s), and training points
ax1 = plt.subplot(211)
plt.plot(Xtrain, Ytrain, 'r+', ms=20) # training points
plt.xlim(min(Xtest), max(Xtest))
plt.ylim(min(mean_f-(2*p_sd)-(p_sd/2)), max(mean_f+(2*p_sd)+(p_sd/2)))
if Ytest is not None:
plt.plot(Xtest, Ytest, 'b', label='Y') # true function
plt.plot(Xtest, mean_f, 'r--', lw=2, label='mean') # mean function
plt.fill_between(Xtest, mean_f-(2*p_sd), mean_f+(2*p_sd), color='#87cefa') # uncertainty
plt.legend()
# Plot 10 draws from posterior
f = p_mean + np.dot(cov_post, np.random.normal(size=(Xtest.shape[0],10)))
ax2 = plt.subplot(212, sharex=ax1)
plt.xlim(min(Xtest), max(Xtest))
plt.plot(Xtest, f)
plt.plot(Xtrain, Ytrain, 'r+', ms=20) # new points
plt.title('Ten samples')
plt.tight_layout()
plt.show()
示例12: plot_learning_curve
def plot_learning_curve(estimator, title, X, y, ylim=None, cv=None, n_jobs=1, train_sizes=np.linspace(0.1, 1.0, 5)):
plt.figure()
plt.title(title)
if ylim is not None:
plt.ylim(*ylim)
plt.xlabel("Training examples")
plt.ylabel("Score")
train_sizes, train_scores, test_scores = learning_curve(
estimator, X, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes
)
train_scores_mean = np.mean(train_scores, axis=1)
train_scores_std = np.std(train_scores, axis=1)
test_scores_mean = np.mean(test_scores, axis=1)
test_scores_std = np.std(test_scores, axis=1)
plt.grid()
plt.fill_between(
train_sizes, train_scores_mean - train_scores_std, train_scores_mean + train_scores_std, alpha=0.1, color="r"
)
plt.fill_between(
train_sizes, test_scores_mean - test_scores_std, test_scores_mean + test_scores_std, alpha=0.1, color="g"
)
plt.plot(train_sizes, train_scores_mean, "o-", color="r", label="Training score")
plt.plot(train_sizes, test_scores_mean, "o-", color="g", label="Cross-validation score")
plt.legend(loc="best")
return plt
示例13: m_errorplot
def m_errorplot(x, Y, L, U):
Y = np.atleast_2d(Y)
L = np.atleast_2d(L)
U = np.atleast_2d(U)
M = Y.shape[-2]
## print(np.shape(Y))
## print(np.shape(L))
## print(np.shape(U))
## print(np.shape(M))
for i in range(M):
plt.subplot(M,1,i+1)
lower = Y[i] - L[i]
upper = Y[i] + U[i]
#print(upper-lower)
#if np.any(lower>=upper):
#print('WTF?!')
plt.fill_between(x,
upper,
lower,
#where=(upper>=lower),
facecolor=(0.6,0.6,0.6,1),
edgecolor=(0,0,0,0),
#edgecolor=(0.6,0.6,0.6,1),
linewidth=0,
interpolate=True)
plt.plot(x, Y[i], color=(0,0,0,1))
plt.ylabel(str(i))
示例14: plot
def plot(self):
"""
Plot input current, recorded voltage, voltage after AEC (is applicable) and detected spike times (if applicable)
"""
time = self.getTime()
plt.figure(figsize=(10,4), facecolor='white')
plt.subplot(2,1,1)
plt.plot(time,self.I, 'gray')
plt.ylabel('I (nA)')
plt.subplot(2,1,2)
plt.plot(time,self.V_rec, 'black')
if self.AEC_flag :
plt.plot(time,self.V, 'red')
if self.spks_flag :
plt.plot(self.getSpikeTimes(),np.zeros(len(self.spks)), '.', color='blue')
# Plot ROI (region selected for performing operations)
ROI_vector = 100.0*np.ones(len(self.V))
ROI_vector[self.getROI() ] = -100.0
plt.fill_between(self.getTime(), ROI_vector, -100.0, color='0.2')
plt.ylim([min(self.V)-5.0, max(self.V)+5.0])
plt.ylabel('V rec (mV)')
plt.xlabel('Time (ms)')
plt.show()
示例15: __spatialaverages__
def __spatialaverages__(cr,path,selector=lambda x:x.yhead,
ylabel='y (cm)',xlim=None,ylim=None):
if not os.path.exists(path):
os.makedirs(path)
cut = getballistictrials(cr)
sessions = cut[cut.trial > 0].groupby(level=['subject','session'])
for (subject,session),group in sessions:
fig = plt.figure()
subjectpath = os.path.join(activitymovies.datafolder,subject)
sact = activitytables.read_subjects(subjectpath,days=[session])
x,y,yerr = activitytables.spatialaverage(sact,group,selector)
activityplots.trajectoryplot(sact,group,alpha=0.2,flip=True,
selector=selector)
plt.fill_between(x,y-yerr,y+yerr)
if xlim is not None:
plt.xlim(xlim)
if ylim is not None:
plt.ylim(ylim)
plt.xlabel('x (cm)')
plt.ylabel(ylabel)
plt.title(str.format('{0} (session {1})',subject,session))
fname = str.format("{0}_session_{1}_trajectories.png",
subject, session)
fpath = os.path.join(path,subject)
if not os.path.exists(fpath):
os.makedirs(fpath)
fpath = os.path.join(fpath,fname)
plt.savefig(fpath)
plt.close(fig)