本文整理汇总了Python中seaborn.set_style方法的典型用法代码示例。如果您正苦于以下问题:Python seaborn.set_style方法的具体用法?Python seaborn.set_style怎么用?Python seaborn.set_style使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类seaborn
的用法示例。
在下文中一共展示了seaborn.set_style方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _plot_spectra
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def _plot_spectra(outpath, typ, savefig=True):
spec = alf.io.load_object(outpath, '_iblqc_ephysSpectralDensity' + typ.upper())
sns.set_style("whitegrid")
plt.figure(figsize=[9, 4.5])
ax = plt.axes()
ax.plot(spec['freqs'], 20 * np.log10(spec['power'] + 1e-14),
linewidth=0.5, color=[0.5, 0.5, 0.5])
ax.plot(spec['freqs'], 20 * np.log10(np.median(spec['power'] + 1e-14, axis=1)), label='median')
ax.set_xlabel(r'Frequency (Hz)')
ax.set_ylabel(r'dB rel to $V^2.$Hz$^{-1}$')
if typ == 'ap':
ax.set_ylim([-275, -125])
elif typ == 'lf':
ax.set_ylim([-260, -60])
ax.legend()
if savefig:
plt.savefig(outpath / (typ + '_spec.png'), dpi=150)
示例2: image
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def image(path: str, costs: Dict[str, int]) -> str:
ys = ['0', '1', '2', '3', '4', '5', '6', '7+', 'X']
xs = [costs.get(k, 0) for k in ys]
sns.set_style('white')
sns.set(font='Concourse C3', font_scale=3)
g = sns.barplot(ys, xs, palette=['#cccccc'] * len(ys))
g.axes.yaxis.set_ticklabels([])
rects = g.patches
sns.set(font='Concourse C3', font_scale=2)
for rect, label in zip(rects, xs):
if label == 0:
continue
height = rect.get_height()
g.text(rect.get_x() + rect.get_width()/2, height + 0.5, label, ha='center', va='bottom')
g.margins(y=0, x=0)
sns.despine(left=True, bottom=True)
g.get_figure().savefig(path, transparent=True, pad_inches=0, bbox_inches='tight')
plt.clf() # Clear all data from matplotlib so it does not persist across requests.
return path
示例3: main
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def main():
logging.basicConfig(level=logging.DEBUG)
output_dir = "data/density/visualize"
os.makedirs(output_dir, exist_ok=True)
styles = ["paper", "density_twocol"]
sns.set_style("whitegrid")
for style in styles:
plt.style.use(vis_styles.STYLES[style])
plot_heatmaps(output_dir)
plot_comparative_densities(output_dir)
bar_chart(
ENV_NAMES,
victim_id="1",
n_components=20,
covariance="full",
savefile=f"{output_dir}/bar_chart.pdf",
)
示例4: visualize_score
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def visualize_score(command, styles, tb_dir, score_paths, fig_dir):
baseline = [util.load_datasets(path) for path in score_paths]
baseline = pd.concat(baseline)
sns.set_style("whitegrid")
for style in styles:
plt.style.use(vis_styles.STYLES[style])
out_paths = command(tb_dir, baseline)
for out_path in out_paths:
visualize_training_ex.add_artifact(filename=out_path)
for observer in visualize_training_ex.observers:
if hasattr(observer, "dir"):
logger.info(f"Copying from {observer.dir} to {fig_dir}")
copy_tree(observer.dir, fig_dir)
break
示例5: plot_avg_return
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def plot_avg_return(file_name, granularity):
plotting_data = torch.load(file_name + "_processed_data")
returns = plotting_data['returns']
unique_frames = plotting_data['unique_frames']
x_len = len(unique_frames)
x_index = [i for i in numpy.arange(0, x_len, granularity)]
x = unique_frames[::granularity]
y = numpy.transpose(numpy.array(returns)[x_index, :])
f, ax = plt.subplots(1, 1, figsize=[3, 2], dpi=300)
sns.set_style("ticks")
sns.set_context("paper")
# Find the order of magnitude of the last frame
order = int(math.log10(unique_frames[-1]))
range_frames = int(unique_frames[-1]/ (10**order))
sns.tsplot(data=y, time=numpy.array(x)/(10**order), color='b')
ax.set_xticks(numpy.arange(range_frames + 1))
plt.show()
f.savefig(file_name + "_avg_return.pdf", bbox_inches="tight")
plt.close(f)
示例6: on_train_begin
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def on_train_begin(self, logs={}):
sns.set_style("whitegrid")
sns.set_style("whitegrid", {"grid.linewidth": 0.5,
"lines.linewidth": 0.5,
"axes.linewidth": 0.5})
flatui = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e",
"#2ecc71"]
sns.set_palette(sns.color_palette(flatui))
# flatui = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"]
# sns.set_palette(sns.color_palette("Set2", 10))
plt.ion() # set plot to animated
width = self.width * (1 + len(self.get_metrics(logs)))
height = self.height
self.fig = plt.figure(figsize=(width, height))
# move it to the upper left corner
move_figure(self.fig, 25, 25)
示例7: plot_kim_curve
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def plot_kim_curve(tmp):
sns.set_context("notebook", font_scale=1.5, rc={"lines.linewidth": 5})
sns.set_style("darkgrid")
plt.figure(figsize=(20, 10))
plt.hold('on')
plt.plot(np.linspace(0, 0.3, 100), tmp['kc_avg'])
plt.ylim([0, 1])
# plt.figure(figsize=(10,5))
# plt.hold('on')
# legend = []
# for k,v in bench_res.iteritems():
# plt.plot(np.linspace(0, 0.3, 100), v['kc_avg'])
# legend.append(k)
# plt.ylim([0, 1])
# plt.legend(legend, loc='lower right')
示例8: __init__
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def __init__(self, path, games, logger, suffix):
super(WordVsQuestion, self).__init__(path, self.__class__.__name__, suffix)
w_by_q = []
for game in games:
for q in game.questions:
q = re.sub('[?]', '', q)
words = re.findall(r'\w+', q)
w_by_q.append(len(words))
sns.set_style("whitegrid", {"axes.grid": False})
# ratio question/words
f = sns.distplot(w_by_q, norm_hist=True, kde=False, bins=np.arange(2.5, 15.5, 1), color="g")
f.set_xlabel("Number of words", {'size': '14'})
f.set_ylabel("Ratio of questions", {'size': '14'})
f.set_xlim(2.5, 14.5)
f.set_ylim(bottom=0)
示例9: __init__
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def __init__(self, path, games, logger, suffix):
super(QuestionVsDialogue, self).__init__(path, self.__class__.__name__, suffix)
q_by_d = []
for game in games:
q_by_d.append(len(game.questions))
sns.set_style("whitegrid", {"axes.grid": False})
#ratio question/dialogues
f = sns.distplot(q_by_d, norm_hist =True, kde=False, bins=np.arange(0.5, 25.5, 1))
f.set_xlim(0.5,25.5)
f.set_ylim(bottom=0)
f.set_xlabel("Number of questions", {'size':'14'})
f.set_ylabel("Ratio of dialogues", {'size':'14'})
示例10: _run_interface
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def _run_interface(self, runtime):
import matplotlib
matplotlib.use('Agg')
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('white')
plt.rcParams['svg.fonttype'] = 'none'
plt.rcParams['image.interpolation'] = 'nearest'
data = self._load_data(self.inputs.data)
out_name = fname_presuffix(self.inputs.data,
suffix='.' + self.inputs.image_type,
newpath=runtime.cwd,
use_ext=False)
self._visualize(data, out_name)
self._results['figure'] = out_name
return runtime
示例11: configure_plt
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def configure_plt():
rc('font', **{'family': 'sans-serif',
'sans-serif': ['Computer Modern Roman']})
params = {'axes.labelsize': 12,
'font.size': 12,
'legend.fontsize': 12,
'xtick.labelsize': 10,
'ytick.labelsize': 10,
'text.usetex': True,
'figure.figsize': (8, 6)}
plt.rcParams.update(params)
sns.set_palette('colorblind')
sns.set_context("poster")
sns.set_style("ticks")
示例12: _plot_spectra
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def _plot_spectra(outpath, typ, savefig=True):
'''
TODO document this function
'''
spec = alf.io.load_object(outpath, '_spikeglx_ephysQcFreq' + typ.upper())
# hack to ensure a single key name
if 'power.probe_00' in spec.keys():
spec['power'] = spec.pop('power.probe_00')
spec['freq'] = spec.pop('freq.probe_00')
elif 'power.probe_01' in spec.keys():
spec['power'] = spec.pop('power.probe_01')
spec['freq'] = spec.pop('freq.probe_01')
# plot
sns.set_style("whitegrid")
plt.figure(figsize=[9, 4.5])
ax = plt.axes()
ax.plot(spec['freq'], 20 * np.log10(spec['power'] + 1e-14),
linewidth=0.5, color=[0.5, 0.5, 0.5])
ax.plot(spec['freq'], 20 * np.log10(np.median(spec['power'] + 1e-14, axis=1)), label='median')
ax.set_xlabel(r'Frequency (Hz)')
ax.set_ylabel(r'dB rel to $V^2.$Hz$^{-1}$')
if typ == 'ap':
ax.set_ylim([-275, -125])
elif typ == 'lf':
ax.set_ylim([-260, -60])
ax.legend()
ax.set_title(outpath)
if savefig:
plt.savefig(outpath / (typ + '_spec.png'), dpi=150)
print('saved figure to %s' % (outpath / (typ + '_spec.png')))
示例13: make_slashdot_figures
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def make_slashdot_figures(output_path_prefix, method_name_list, slashdot_mse, slashdot_jaccard, slashdot_k_list):
sns.set_style("darkgrid")
sns.set_context("paper")
translator = get_method_name_to_legend_name_dict()
slashdot_k_list = list(slashdot_k_list)
fig, axes = plt.subplots(1, 2, sharex=True)
axes[0].set_title("SlashDot Comments")
axes[1].set_title("SlashDot Users")
plt.locator_params(nbins=8)
# Comments
for m, method in enumerate(method_name_list):
axes[0].set_ylabel("MSE")
axes[0].set_xlabel("Lifetime (sec)")
axes[0].plot(slashdot_k_list[1:],
handle_nan(slashdot_mse[method]["comments"].mean(axis=1))[1:],
label=translator[method])
# Users
for m, method in enumerate(method_name_list):
# axes[1].set_ylabel("MSE")
axes[1].set_xlabel("Lifetime (sec)")
axes[1].plot(slashdot_k_list[1:],
handle_nan(slashdot_mse[method]["users"].mean(axis=1))[1:],
label=translator[method])
axes[1].legend(loc="upper right")
# plt.show()
plt.savefig(output_path_prefix + "_mse_slashdot_SNOW" + ".png", format="png")
plt.savefig(output_path_prefix + "_mse_slashdot_SNOW" + ".eps", format="eps")
示例14: make_barrapunto_figures
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def make_barrapunto_figures(output_path_prefix, method_name_list, barrapunto_mse, barrapunto_jaccard, barrapunto_k_list):
sns.set_style("darkgrid")
sns.set_context("paper")
translator = get_method_name_to_legend_name_dict()
barrapunto_k_list = list(barrapunto_k_list)
fig, axes = plt.subplots(1, 2, sharex=True)
axes[0].set_title("BarraPunto Comments")
axes[1].set_title("BarraPunto Users")
plt.locator_params(nbins=8)
# Comments
for m, method in enumerate(method_name_list):
axes[0].set_ylabel("MSE")
axes[0].set_xlabel("Lifetime (sec)")
axes[0].plot(barrapunto_k_list[1:],
handle_nan(barrapunto_mse[method]["comments"].mean(axis=1))[1:],
label=translator[method])
# Users
for m, method in enumerate(method_name_list):
# axes[1].set_ylabel("MSE")
axes[1].set_xlabel("Lifetime (sec)")
axes[1].plot(barrapunto_k_list[1:],
handle_nan(barrapunto_mse[method]["users"].mean(axis=1))[1:],
label=translator[method])
axes[1].legend(loc="upper right")
# plt.show()
plt.savefig(output_path_prefix + "_mse_barrapunto_SNOW" + ".png", format="png")
plt.savefig(output_path_prefix + "_mse_barrapunto_SNOW" + ".eps", format="eps")
示例15: compare_classifiers_line_plot
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import set_style [as 别名]
def compare_classifiers_line_plot(
xs,
scores,
metric,
algorithm_names=None,
title=None,
filename=None
):
sns.set_style('whitegrid')
colors = plt.get_cmap('tab10').colors
fig, ax = plt.subplots()
ax.grid(which='both')
ax.grid(which='minor', alpha=0.5)
ax.grid(which='major', alpha=0.75)
if title is not None:
ax.set_title(title)
ax.set_xticks(xs)
ax.set_xticklabels(xs)
ax.set_xlabel('k')
ax.set_ylabel(metric)
for i, score in enumerate(scores):
ax.plot(xs, score,
label=algorithm_names[
i] if algorithm_names is not None and i < len(
algorithm_names) else 'Algorithm {}'.format(i),
color=colors[i], linewidth=3, marker='o')
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
plt.tight_layout()
ludwig.contrib.contrib_command("visualize_figure", plt.gcf())
if filename:
plt.savefig(filename)
else:
plt.show()