本文整理汇总了Python中seaborn.plotting_context方法的典型用法代码示例。如果您正苦于以下问题:Python seaborn.plotting_context方法的具体用法?Python seaborn.plotting_context怎么用?Python seaborn.plotting_context使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类seaborn
的用法示例。
在下文中一共展示了seaborn.plotting_context方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: customize
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import plotting_context [as 别名]
def customize(func):
"""
修饰器,设置输出图像内容与风格
"""
@wraps(func)
def call_w_context(*args, **kwargs):
set_context = kwargs.pop("set_context", True)
if set_context:
color_palette = sns.color_palette("colorblind")
with plotting_context(), axes_style(), color_palette:
sns.despine(left=True)
return func(*args, **kwargs)
else:
return func(*args, **kwargs)
return call_w_context
示例2: plotting_context
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import plotting_context [as 别名]
def plotting_context(
context: str = "notebook", font_scale: float = 1.5, rc: dict = None
):
"""
创建默认画图板样式
参数
---
:param context: seaborn 样式
:param font_scale: 设置字体大小
:param rc: 配置标签
"""
if rc is None:
rc = {}
rc_default = {"lines.linewidth": 1.5}
# 如果没有默认设置,增加默认设置
for name, val in rc_default.items():
rc.setdefault(name, val)
return sns.plotting_context(context=context, font_scale=font_scale, rc=rc)
示例3: customize
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import plotting_context [as 别名]
def customize(func):
@wraps(func)
def call_w_context(*args, **kwargs):
if not PlotConfig.FONT_SETTED:
_use_chinese(True)
set_context = kwargs.pop('set_context', True)
if set_context:
with plotting_context(), axes_style():
sns.despine(left=True)
return func(*args, **kwargs)
else:
return func(*args, **kwargs)
return call_w_context
示例4: _distplot
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import plotting_context [as 别名]
def _distplot(
data,
labels=None,
direction="out",
title="",
context="talk",
font_scale=1,
figsize=(10, 5),
palette="Set1",
xlabel="",
ylabel="Density",
):
plt.figure(figsize=figsize)
ax = plt.gca()
palette = sns.color_palette(palette)
plt_kws = {"cumulative": True}
with sns.plotting_context(context=context, font_scale=font_scale):
if labels is not None:
categories, counts = np.unique(labels, return_counts=True)
for i, cat in enumerate(categories):
cat_data = data[np.where(labels == cat)]
if counts[i] > 1 and cat_data.min() != cat_data.max():
x = np.sort(cat_data)
y = np.arange(len(x)) / float(len(x))
plt.plot(x, y, label=cat, color=palette[i])
else:
ax.axvline(cat_data[0], label=cat, color=palette[i])
plt.legend()
else:
if data.min() != data.max():
sns.distplot(data, hist=False, kde_kws=plt_kws)
else:
ax.axvline(data[0])
plt.title(title)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
return ax
示例5: plotting_context
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import plotting_context [as 别名]
def plotting_context(context='notebook', font_scale=1.5, rc=None):
if rc is None:
rc = {}
rc_default = {'lines.linewidth': 1.5}
for name, val in rc_default.items():
rc.setdefault(name, val)
return sns.plotting_context(context=context, font_scale=font_scale, rc=rc)
示例6: create_data_summary_plot
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import plotting_context [as 别名]
def create_data_summary_plot(data_df, subplot_side_length = 3.0, subplot_font_scale = 0.5, max_title_length = 30):
df = pd.DataFrame(data_df)
# determine number of plots
n_plots = len(data_df.columns)
n_cols = int(np.round(np.sqrt(n_plots)))
n_rows = int(np.round(n_plots / n_cols))
assert n_cols * n_rows >= n_plots
colnames = df.columns.tolist()
plot_titles = [c[:max_title_length] for c in colnames]
f, axarr = plt.subplots(n_rows, n_cols, figsize=(subplot_side_length * n_rows, subplot_side_length * n_cols), sharex = False, sharey = True)
sns.despine(left = True)
n = 0
with sns.plotting_context(font_scale = subplot_font_scale):
for i in range(n_rows):
for j in range(n_cols):
ax = axarr[i][j]
if n < n_plots:
bar_color = 'g' if n == 0 else 'b'
vals = df[colnames[n]]
unique_vals = np.unique(vals)
sns.distplot(a = vals, kde = False, color = bar_color, ax = axarr[i][j], hist_kws = {'edgecolor': "k", 'linewidth': 0.5})
ax.xaxis.label.set_visible(False)
ax.text(.5, .9, plot_titles[n], horizontalalignment = 'center', transform = ax.transAxes, fontsize = 10)
if len(unique_vals) == 2:
ax.set_xticks(unique_vals)
n += 1
else:
ax.set_visible(False)
plt.tight_layout()
plt.show()
return f, axarr