本文整理匯總了Python中seaborn.kdeplot方法的典型用法代碼示例。如果您正苦於以下問題:Python seaborn.kdeplot方法的具體用法?Python seaborn.kdeplot怎麽用?Python seaborn.kdeplot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類seaborn
的用法示例。
在下文中一共展示了seaborn.kdeplot方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: joint_plot
# 需要導入模塊: import seaborn [as 別名]
# 或者: from seaborn import kdeplot [as 別名]
def joint_plot(x, y, xlabel=None,
ylabel=None, xlim=None, ylim=None,
loc="best", color='#0485d1',
size=8, markersize=50, kind="kde",
scatter_color="r"):
with sns.axes_style("darkgrid"):
if xlabel and ylabel:
g = SubsampleJointGrid(xlabel, ylabel,
data=DataFrame(data={xlabel: x, ylabel: y}),
space=0.1, ratio=2, size=size, xlim=xlim, ylim=ylim)
else:
g = SubsampleJointGrid(x, y, size=size,
space=0.1, ratio=2, xlim=xlim, ylim=ylim)
g.plot_joint(sns.kdeplot, shade=True, cmap="Blues")
g.plot_sub_joint(plt.scatter, 1000, s=20, c=scatter_color, alpha=0.3)
g.plot_marginals(sns.distplot, kde=False, rug=False)
g.annotate(ss.pearsonr, fontsize=25, template="{stat} = {val:.2g}\np = {p:.2g}")
g.ax_joint.set_yticklabels(g.ax_joint.get_yticks())
g.ax_joint.set_xticklabels(g.ax_joint.get_xticks())
return g
示例2: astro_oligo_joint
# 需要導入模塊: import seaborn [as 別名]
# 或者: from seaborn import kdeplot [as 別名]
def astro_oligo_joint(X, genes, gene1, gene2, labels, focus, name):
X = X.toarray()
gidx1 = list(genes).index(gene1)
gidx2 = list(genes).index(gene2)
idx = labels == focus
x1 = X[(idx, gidx1)]
x2 = X[(idx, gidx2)]
plt.figure()
sns.jointplot(
x1, x2, kind='scatter', space=0, alpha=0.3
).plot_joint(sns.kdeplot, zorder=0, n_levels=10)
plt.savefig('{}_joint_{}_{}_{}.png'.format(name, focus, gene1, gene2))
示例3: plot_activations
# 需要導入模塊: import seaborn [as 別名]
# 或者: from seaborn import kdeplot [as 別名]
def plot_activations(a_s,a_t,save_name):
"""
activation visualization via seaborn library
"""
n_dim=a_s.shape[1]
n_rows=1
n_cols=int(n_dim/n_rows)
fig, axs = plt.subplots(nrows=n_rows,ncols=n_cols, sharey=True,
sharex=True)
for k,ax in enumerate(axs.reshape(-1)):
if k>=n_dim:
continue
sns.kdeplot(a_t[:,k],ax=ax, shade=True, label='target',
legend=False, color='0.4',bw=0.03)
sns.kdeplot(a_s[:,k],ax=ax, shade=True, label='source',
legend=False, color='0',bw=0.03)
plt.setp(ax.xaxis.get_ticklabels(),fontsize=10)
plt.setp(ax.yaxis.get_ticklabels(),fontsize=10)
fig.set_figheight(3)
plt.setp(axs, xticks=[0, 0.5, 1])
plt.setp(axs, ylim=[0,10])
plt.savefig(save_name)
# load dataset
示例4: plot_posterior
# 需要導入模塊: import seaborn [as 別名]
# 或者: from seaborn import kdeplot [as 別名]
def plot_posterior(model, variables, number_samples=1000):
# Get samples
sample = model.get_sample(number_samples)
post_sample = model.get_posterior_sample(number_samples)
# Join samples
sample["Mode"] = "Prior"
post_sample["Mode"] = "Posterior"
subsample = sample[variables + ["Mode"]]
post_subsample = post_sample[variables + ["Mode"]]
joint_subsample = subsample.append(post_subsample)
# Plot posterior
warnings.filterwarnings('ignore')
g = sns.PairGrid(joint_subsample, hue="Mode")
g = g.map_offdiag(sns.kdeplot)
g = g.map_diag(sns.kdeplot, lw=3, shade=True)
g = g.add_legend()
warnings.filterwarnings('default')
示例5: plotCorrelation
# 需要導入模塊: import seaborn [as 別名]
# 或者: from seaborn import kdeplot [as 別名]
def plotCorrelation(stats):
#columnsToDrop = ['sleep_interval_max_len', 'sleep_interval_min_len',
# 'sleep_interval_avg_len', 'sleep_inefficiency',
# 'sleep_hours', 'total_hours']
#stats = stats.drop(columnsToDrop, axis=1)
g = sns.PairGrid(stats)
def corrfunc(x, y, **kws):
r, p = scipystats.pearsonr(x, y)
ax = plt.gca()
ax.annotate("r = {:.2f}".format(r),xy=(.1, .9), xycoords=ax.transAxes)
ax.annotate("p = {:.2f}".format(p),xy=(.2, .8), xycoords=ax.transAxes)
if p>0.04:
ax.patch.set_alpha(0.1)
g.map_upper(plt.scatter)
g.map_diag(plt.hist)
g.map_lower(sns.kdeplot, cmap="Blues_d")
g.map_upper(corrfunc)
sns.plt.show()
示例6: comparative_densities
# 需要導入模塊: import seaborn [as 別名]
# 或者: from seaborn import kdeplot [as 別名]
def comparative_densities(
env, victim_id, n_components, covariance, cutoff_point=None, savefile=None, **kwargs
):
"""PDF of different opponents density distribution.
For unspecified parameters, see get_full_directory.
:param cutoff_point: (float): left x-limit.
:param savefile: (None or str) path to save figure to.
:param kwargs: (dict) passed through to sns.kdeplot."""
df = load_metadata(env, victim_id, n_components, covariance)
fig = plt.figure(figsize=(10, 7))
grped = df.groupby("opponent_id")
for name, grp in grped:
# clean up random_none to just random
name = name.replace("_none", "")
avg_log_proba = np.mean(grp["log_proba"])
sns.kdeplot(grp["log_proba"], label=f"{name}: {round(avg_log_proba, 2)}", **kwargs)
xmin, xmax = plt.xlim()
xmin = max(xmin, cutoff_point)
plt.xlim((xmin, xmax))
plt.suptitle(f"{env} Densities, Victim Zoo {victim_id}: Trained on Zoo 1", y=0.95)
plt.title("Avg Log Proba* in Legend")
if savefile is not None:
fig.savefig(f"{savefile}.pdf")
示例7: plot_nn_dist_distr
# 需要導入模塊: import seaborn [as 別名]
# 或者: from seaborn import kdeplot [as 別名]
def plot_nn_dist_distr(params):
"""
Plot distributions of nearest neighbor distances
"""
import matplotlib.pyplot as plt
import seaborn as sns
split_set, aa_dist, ii_dist, ai_dist, ia_dist, thresholds = params[:]
vaI, viI, taI, tiI = split_set
# get the slices of the distance matrices
aTest_aTrain_D = aa_dist[ np.ix_( vaI, taI ) ]
aTest_iTrain_D = ai_dist[ np.ix_( vaI, tiI ) ]
iTest_aTrain_D = ia_dist[ np.ix_( viI, taI ) ]
iTest_iTrain_D = ii_dist[ np.ix_( viI, tiI ) ]
aa_nn_dist = np.min(aTest_aTrain_D, axis=1)
ai_nn_dist = np.min(aTest_iTrain_D, axis=1)
ia_nn_dist = np.min(iTest_aTrain_D, axis=1)
ii_nn_dist = np.min(iTest_iTrain_D, axis=1)
# Plot distributions of nearest-neighbor distances
fig, axes = plt.subplots(2, 2, figsize=(12,12))
sns.kdeplot(aa_nn_dist, ax=axes[0,0])
axes[0,0].set_title('AA')
sns.kdeplot(ai_nn_dist, ax=axes[0,1])
axes[0,1].set_title('AI')
sns.kdeplot(ia_nn_dist, ax=axes[1,0])
axes[1,0].set_title('II')
sns.kdeplot(ii_nn_dist, ax=axes[1,1])
axes[1,1].set_title('IA')
#*******************************************************************************************************************************************
示例8: plot_density
# 需要導入模塊: import seaborn [as 別名]
# 或者: from seaborn import kdeplot [as 別名]
def plot_density(model, variables, number_samples=2000):
sample = model.get_sample(number_samples)
warnings.filterwarnings('ignore')
g = sns.PairGrid(sample[variables])
g = g.map_offdiag(sns.kdeplot)
g = g.map_diag(sns.kdeplot, lw=3, shade=True)
g = g.add_legend()
warnings.filterwarnings('default')
示例9: _joint_grid
# 需要導入模塊: import seaborn [as 別名]
# 或者: from seaborn import kdeplot [as 別名]
def _joint_grid(col_x, col_y, col_k, df, k_is_color=False, scatter_alpha=.85):
def colored_kde(x, y, c=None):
def kde(*args, **kwargs):
args = (x, y)
if c is not None:
kwargs['c'] = c
kwargs['alpha'] = scatter_alpha
sns.kdeplot(*args, **kwargs)
return kde
g = sns.JointGrid(
x=col_x,
y=col_y,
data=df
)
color = None
legends = []
for name, df_group in df.groupby(col_k):
legends.append(name)
if k_is_color:
color=name
g.plot_joint(
colored_kde(df_group[col_x], df_group[col_y], color),
)
sns.kdeplot(
df_group[col_x].values,
ax=g.ax_marg_x,
color=color,
shade=True
)
sns.kdeplot(
df_group[col_y].values,
ax=g.ax_marg_y,
color=color,
shade=True,
vertical=True
)
plt.legend(legends)
示例10: plot_breakpoints_hist
# 需要導入模塊: import seaborn [as 別名]
# 或者: from seaborn import kdeplot [as 別名]
def plot_breakpoints_hist(v1, v2, v1_name, v2_name):
sns.kdeplot(v1, color="b", label=v1_name, shade=True, legend=False)
sns.kdeplot(v2, color="r", label=v2_name, shade=True, legend=False)
pyplot.legend(loc="upper right")
示例11: plot_tensor
# 需要導入模塊: import seaborn [as 別名]
# 或者: from seaborn import kdeplot [as 別名]
def plot_tensor(tensor, ax, name, config):
tensor = torch.abs(tensor)
#import ipdb as pdb; pdb.set_trace()
#print(tensor.shape)
ax.set_title(name, fontsize="small")
ax.xaxis.set_tick_params(labelsize=6)
ax.yaxis.set_tick_params(labelsize=6)
if config["quantization"].lower() == "fixed":
#ax.hist(quant.to_fixed_point(tensor, config["weight_i_width"], config["weight_f_width"]).detach().numpy(), normed=True)
sns.distplot(quant.to_fixed_point(tensor, config["weight_i_width"], config["weight_f_width"]).detach().numpy(), ax=ax, kde_kws={"color": "r"})
#sns.kdeplot(quant.to_fixed_point(tensor, config["weight_i_width"], config["weight_f_width"]).detach().numpy(), ax=ax, shade=True)
elif config["quantization"].lower() == "normal":
sns.distplot(tensor.detach().numpy(), ax=ax, kde_kws={"color": "r"})
開發者ID:hossein1387,項目名稱:U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation,代碼行數:15,代碼來源:model_visualizer.py
示例12: _plot_kde
# 需要導入模塊: import seaborn [as 別名]
# 或者: from seaborn import kdeplot [as 別名]
def _plot_kde(output_res, pick_rows, color_palette, alpha=0.5):
num_clusters = len(set(pick_rows))
for ci in range(num_clusters):
cur_plot_rows = pick_rows == ci
cur_cmap = sns.light_palette(color_palette[ci], as_cmap=True)
sns.kdeplot(output_res[cur_plot_rows, 0], output_res[cur_plot_rows, 1], cmap=cur_cmap, shade=True, alpha=alpha,
shade_lowest=False)
centroid = output_res[cur_plot_rows, :].mean(axis=0)
plt.annotate('%s' % ci, xy=centroid, xycoords='data', alpha=0.5,
horizontalalignment='center', verticalalignment='center')