本文整理匯總了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