本文整理汇总了Python中matplotlib.pyplot.fill_between方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.fill_between方法的具体用法?Python pyplot.fill_between怎么用?Python pyplot.fill_between使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.fill_between方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_3
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def plot_3(data):
x = data.Iteration.unique()
y_mean = data.groupby('Iteration').mean()
y_std = data.groupby('Iteration').std()
sns.set(style="darkgrid", font_scale=1.5)
value = 'AverageReturn'
plt.plot(x, y_mean[value], label=data['Condition'].unique()[0] + '_train');
plt.fill_between(x, y_mean[value] - y_std[value], y_mean[value] + y_std[value], alpha=0.2);
value = 'ValAverageReturn'
plt.plot(x, y_mean[value], label=data['Condition'].unique()[0] + '_test');
plt.fill_between(x, y_mean[value] - y_std[value], y_mean[value] + y_std[value], alpha=0.2);
plt.xlabel('Iteration')
plt.ylabel('AverageReturn')
plt.legend(loc='best')
示例2: dosplot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def dosplot (filename = None, data = None, fermi = None):
if (filename is not None): data = np.loadtxt(filename)
elif (data is not None): data = data
import matplotlib.pyplot as plt
from matplotlib import rc
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.plot(data.T[0], data.T[1], label='MF Spin-UP', linestyle=':',color='r')
plt.fill_between(data.T[0], 0, data.T[1], facecolor='r',alpha=0.1, interpolate=True)
plt.plot(data.T[0], data.T[2], label='QP Spin-UP',color='r')
plt.fill_between(data.T[0], 0, data.T[2], facecolor='r',alpha=0.5, interpolate=True)
plt.plot(data.T[0],-data.T[3], label='MF Spin-DN', linestyle=':',color='b')
plt.fill_between(data.T[0], 0, -data.T[3], facecolor='b',alpha=0.1, interpolate=True)
plt.plot(data.T[0],-data.T[4], label='QP Spin-DN',color='b')
plt.fill_between(data.T[0], 0, -data.T[4], facecolor='b',alpha=0.5, interpolate=True)
if (fermi!=None): plt.axvline(x=fermi ,color='k', linestyle='--') #label='Fermi Energy'
plt.axhline(y=0,color='k')
plt.title('Total DOS', fontsize=20)
plt.xlabel('Energy (eV)', fontsize=15)
plt.ylabel('Density of States (electron/eV)', fontsize=15)
plt.legend()
plt.savefig("dos_eigen.svg", dpi=900)
plt.show()
示例3: save_precision_recall_curve
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def save_precision_recall_curve(eval_labels, pred_labels, average_precision, smell, config, out_folder, dim, method):
fig = plt.figure()
precision, recall, _ = precision_recall_curve(eval_labels, pred_labels)
step_kwargs = ({'step': 'post'}
if 'step' in signature(plt.fill_between).parameters
else {})
plt.step(recall, precision, color='b', alpha=0.2,
where='post')
plt.fill_between(recall, precision, alpha=0.2, color='b', **step_kwargs)
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.ylim([0.0, 1.05])
plt.xlim([0.0, 1.0])
if isinstance(config, cfg.CNN_config):
title_str = smell + " (" + method + " - " + dim + ") - L=" + str(config.layers) + ", E=" + str(config.epochs) + ", F=" + str(config.filters) + \
", K=" + str(config.kernel) + ", PW=" + str(config.pooling_window) + ", AP={0:0.2f}".format(average_precision)
# plt.title(title_str)
# plt.show()
file_name = get_plot_file_name(smell, config, out_folder, dim, method, "_prc_")
fig.savefig(file_name)
示例4: plot_eigenval_estimates
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def plot_eigenval_estimates(estimates, label):
"""
estimates = 2D array (num_trials x num_eigenvalues)
x-axis = eigenvalue index
y-axis = eigenvalue estimate
"""
if len(estimates.shape) == 1:
var = np.zeros_like(estimates)
else:
var = np.var(estimates, axis=0)
y = np.mean(estimates, axis=0)
x = list(range(len(y)))
error = np.sqrt(var)
plt.plot(x, y, label=label)
plt.fill_between(x, y-error, y+error, alpha=.2)
示例5: plot_eigenvec_errors
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def plot_eigenvec_errors(true, estimates, label):
"""
plots error for all eigenvector estimates in L2 norm
estimates = (num_trials x num_eigenvalues x num_params)
true = (num_eigenvalues x num_params)
"""
diffs = []
num_eigenvals = true.shape[0]
for i in range(num_eigenvals):
cur_estimates = estimates[:, i, :]
cur_eigenvec = true[i]
diff = compute_eigenvec_cos_similarity(cur_eigenvec, cur_estimates)
diffs.append(diff)
diffs = np.array(diffs).T
var = np.var(diffs, axis=0)
y = np.mean(diffs, axis=0)
x = list(range(len(y)))
error = np.sqrt(var)
plt.plot(x, y, label=label)
plt.fill_between(x, y-error, y+error, alpha=.2)
示例6: plot_gain
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def plot_gain(gain_his,name=None):
#display data
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib as mpl
gain_array = np.asarray(gain_his)
df = pd.DataFrame(gain_his)
mpl.style.use('seaborn')
fig, ax = plt.subplots(figsize=(15,8))
rolling_intv = 60
df_roll=df.rolling(rolling_intv, min_periods=1).mean()
if name != None:
sio.savemat('./data/MUMT(%s)'%name,{'ratio':gain_his})
plt.plot(np.arange(len(gain_array))+1, df_roll, 'b')
plt.fill_between(np.arange(len(gain_array))+1, df.rolling(rolling_intv, min_periods=1).min()[0], df.rolling(rolling_intv, min_periods=1).max()[0], color = 'b', alpha = 0.2)
plt.ylabel('Gain ratio')
plt.xlabel('learning steps')
plt.show()
示例7: plot_total_dos
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def plot_total_dos(self, **kwargs):
"""
Plots the total DOS
Args:
**kwargs: Variables for matplotlib.pylab.plot customization (linewidth, linestyle, etc.)
Returns:
matplotlib.pylab.plot
"""
try:
import matplotlib.pylab as plt
except ImportError:
import matplotlib.pyplot as plt
fig = plt.figure(1, figsize=(6, 4))
ax1 = fig.add_subplot(111)
ax1.set_xlabel("E (eV)", fontsize=14)
ax1.set_ylabel("DOS", fontsize=14)
plt.fill_between(self.energies, self.t_dos, **kwargs)
return plt
示例8: plotGPGO
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def plotGPGO(gpgo, param, index, new=True):
param_value = list(param.values())[0][1]
x_test = np.linspace(param_value[0], param_value[1], 1000).reshape((1000, 1))
y_hat, y_var = gpgo.GP.predict(x_test, return_std=True)
std = np.sqrt(y_var)
l, u = y_hat - 1.96 * std, y_hat + 1.96 * std
if new:
plt.figure()
plt.subplot(5, 1, 1)
plt.fill_between(x_test.flatten(), l, u, alpha=0.2)
plt.plot(x_test.flatten(), y_hat)
plt.subplot(5, 1, index)
a = np.array([-gpgo._acqWrapper(np.atleast_1d(x)) for x in x_test]).flatten()
plt.plot(x_test, a, color=colors[index - 2], label=acq_titles[index - 2])
gpgo._optimizeAcq(method='L-BFGS-B', n_start=1000)
plt.axvline(x=gpgo.best)
plt.legend(loc=0)
示例9: plotGPGO
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def plotGPGO(gpgo, param):
param_value = list(param.values())[0][1]
x_test = np.linspace(param_value[0], param_value[1], 1000).reshape((1000, 1))
hat = gpgo.GP.predict(x_test, return_std=True)
y_hat, y_std = hat[0], np.sqrt(hat[1])
l, u = y_hat - 1.96 * y_std, y_hat + 1.96 * y_std
fig = plt.figure()
r = fig.add_subplot(2, 1, 1)
r.set_title('Fitted Gaussian process')
plt.fill_between(x_test.flatten(), l, u, alpha=0.2)
plt.plot(x_test.flatten(), y_hat, color='red', label='Posterior mean')
plt.legend(loc=0)
a = np.array([-gpgo._acqWrapper(np.atleast_1d(x)) for x in x_test]).flatten()
r = fig.add_subplot(2, 1, 2)
r.set_title('Acquisition function')
plt.plot(x_test, a, color='green')
gpgo._optimizeAcq(method='L-BFGS-B', n_start=1000)
plt.axvline(x=gpgo.best, color='black', label='Found optima')
plt.legend(loc=0)
plt.tight_layout()
plt.savefig(os.path.join(os.getcwd(), 'mthesis_text/figures/chapter3/sine/{}.pdf'.format(i)))
plt.show()
示例10: add_bg_graph
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def add_bg_graph(values, color):
load_coefficient = 0
time_ax = []
load_ax = []
initial_rate = values[0][2]
for i in range(0, len(values)):
if i == 0:
load_coefficient = 0
time_ax.extend([values[i][0], values[i][0]])
load_ax.extend([0, initial_rate])
else:
time_ax.extend([values[i][0], values[i][0]])
load_ax.append(initial_rate + values[i][2] * load_coefficient)
load_coefficient += 1
load_ax.append(initial_rate + values[i][2] * load_coefficient)
if i == len(values) - 1:
time_ax.extend([values[i][1], values[i][1]])
load_ax.extend([initial_rate + values[i][2] * load_coefficient, 0])
plt.fill_between(time_ax, load_ax, facecolor=color, alpha=0.4)
示例11: add_graph
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def add_graph(values, color):
load_coefficient = 0
time_ax = []
load_ax = []
spike_length = get_spike_length(values)
initial_rate = values[0][2]
for i in range(0, len(values)):
if i % spike_length == 0:
load_coefficient = 0
time_ax.extend([values[i][0], values[i][0]])
load_ax.extend([0, initial_rate])
else:
time_ax.extend([values[i][0], values[i][0]])
load_ax.append(initial_rate + values[i][2] * load_coefficient)
load_coefficient += 1
load_ax.append(initial_rate + values[i][2] * load_coefficient)
if (i + 1) % spike_length == 0:
time_ax.extend([values[i][1], values[i][1]])
load_ax.extend([initial_rate + values[i][2] * load_coefficient, 0])
plt.fill_between(time_ax, load_ax, facecolor=color, alpha=0.4)
示例12: viz_trap
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def viz_trap(f, a, b, n, N):
h = (b - a) / float(n)
midpoints = []
for i in range(n + 1):
midpoints.append(f(a + (i * h)))
print midpoints
data = np.zeros(n * N)
for i in range(n):
data[i * N:(i + 1) * N] = np.linspace(midpoints[i],
midpoints[i + 1], N)
x = np.linspace(a, b, n * N)
plt.plot(x, f(x), linewidth=2, color=colorset[-1])
plt.plot(x, data, color=colorset[-2], linestyle='--')
for i in range(n):
plt.plot([h * i, h * i], [0, data[i * N]],
color=colorset[-2], linestyle='--')
plt.fill_between(x, f(x), data, color=colorset[1])
plt.xlabel('x')
plt.ylabel('f(x)')
plt.title('%g segments' % n)
plt.show()
示例13: viz_rect
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def viz_rect(f, a, b, n, N):
h = (b - a) / float(n)
data = []
for i in range(1, n + 1):
for j in range(50):
data.append(f(a + (i - 0.5) * h))
x = np.linspace(a, b, n * N)
plt.plot(x, f(x), linewidth=2, color=colorset[-1])
plt.plot(x, data, color=colorset[-2], linestyle='--')
for i in range(n):
plt.plot([h * i, h * i], [0, data[i * N]],
color=colorset[-2], linestyle='--')
plt.fill_between(x, f(x), data, color=colorset[1])
plt.xlabel('x')
plt.ylabel('f(x)')
plt.title('%g segments' % n)
plt.show()
示例14: plot_loss
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def plot_loss(arr, window=50, figsize=(20, 10), name=None):
def _rolling_window(a, window):
shape = a.shape[:-1] + (a.shape[-1] - window + 1, window)
strides = a.strides + (a.strides[-1],)
return np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides)
arr = np.asarray(arr)
fig, ax = plt.subplots(figsize=figsize)
rolling_mean = np.mean(_rolling_window(arr, 50), 1)
rolling_std = np.std(_rolling_window(arr, 50), 1)
plt.plot(range(len(rolling_mean)), rolling_mean, alpha=0.98, linewidth=0.9)
plt.fill_between(
range(len(rolling_std)),
rolling_mean - rolling_std,
rolling_mean + rolling_std,
alpha=0.5,
)
plt.grid()
plt.xlabel("Iteration #")
plt.ylabel("Loss")
if name is not None:
if not os.path.exists("./plots/"):
os.makedirs("./plots/")
plt.savefig("./plots/{}.png".format(name), format="png", dpi=150)
plt.show()
示例15: __call__
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import fill_between [as 别名]
def __call__(self, args, env):
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import average_precision_score
from sklearn.metrics import precision_recall_curve
from vergeml.plots import load_labels, load_predictions
try:
labels = load_labels(env)
except FileNotFoundError:
raise VergeMLError("Can't plot PR curve - not supported by model.")
nclasses = len(labels)
if args['class'] not in labels:
raise VergeMLError("Unknown class: " + args['class'])
try:
y_test, y_score = load_predictions(env, nclasses)
except FileNotFoundError:
raise VergeMLError("Can't plot PR curve - not supported by model.")
# From:
# https://scikit-learn.org/stable/auto_examples/model_selection/plot_precision_recall.html#sphx-glr-auto-examples-model-selection-plot-precision-recall-py
ix = labels.index(args['class'])
y_test = y_test[:,ix].astype(np.int)
y_score = y_score[:,ix]
precision, recall, _ = precision_recall_curve(y_test, y_score)
average_precision = average_precision_score(y_test, y_score)
plt.step(recall, precision, color='b', alpha=0.2, where='post')
plt.fill_between(recall, precision, alpha=0.2, color='b', step='post')
plt.xlabel('Recall ({})'.format(args['class']))
plt.ylabel('Precision ({})'.format(args['class']))
plt.ylim([0.0, 1.05])
plt.xlim([0.0, 1.0])
plt.title('Precision-Recall curve for @{0}: AP={1:0.2f}'.format(args['@AI'], average_precision))
plt.show()