Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
p1.save(os.path.join(outdir, 'protobowl_hist.pdf'))
# p1.draw()
print('p1 done')
# histogram of accuracy
p2 = ggplot(user_stat, aes(x='result', y='..density..')) \
+ geom_histogram(color='#31a354', fill='#e5f5e0') \
+ geom_density() \
+ labs(x='Accuracy', y='Density') \
+ theme(aspect_ratio=0.3)
p2.save(os.path.join(outdir, 'protobowl_acc.pdf'))
# p2.draw()
print('p2 done')
# histogram of buzzing position
p3 = ggplot(user_stat, aes(x='relative_position', y='..density..')) \
+ geom_histogram(color='#3182bd', fill='#deebf7') \
+ geom_density() \
+ labs(x='Average buzzing position', y='Density') \
+ theme(aspect_ratio=0.3)
p3.save(os.path.join(outdir, 'protobowl_pos.pdf'))
# p3.draw()
print('p3 done')
for i in range(len(color_order)):
for j in dm[facet_var].unique():
dm_sub = dm[(dm[group_by] == color_order[i]) & (dm[facet_var] == j)].sort_values('pos')
p += plotnine.geom_ribbon(data=dm_sub,
mapping=aes(ymin='ci_low_robust',
ymax='ci_high_robust'),
show_legend=False,
fill=list(dm_sub.color_palette.unique())[0],
color=None,
alpha=0.3)
else:
if stat == "mean":
for i in range(len(color_order)):
dm_sub = dm[dm[group_by] == color_order[i]].sort_values('pos')
p += plotnine.geom_ribbon(data=dm_sub,
mapping=aes(ymin='ci_low',
ymax='ci_high'),
show_legend=False,
fill=list(dm_sub.color_palette.unique())[0],
color=None,
alpha=0.3)
elif stat == "median":
for i in range(len(color_order)):
dm_sub = dm[dm[group_by] == color_order[i]].sort_values('pos')
p += plotnine.geom_ribbon(data=dm_sub,
mapping=aes(ymin='ci_low_robust',
ymax='ci_high_robust'),
show_legend=False,
fill=list(dm_sub.color_palette.unique())[0],
color=None,
alpha=0.3)
mat_s = d[['feature_type',
'summed_bp_overlaps_log2_fold_change',
'summed_bp_overlaps_pvalue']]
# Uncomputed pvalue are discarded
mat_s = mat_s.drop(mat_s[mat_s.summed_bp_overlaps_pvalue == -1].index)
# Pval set to 0 are changed to 1e-320
mat_s.loc[mat_s['summed_bp_overlaps_pvalue'] == 0, 'summed_bp_overlaps_pvalue'] = 1e-320
mat_s = mat_s.assign(minus_log10_pvalue=list(-np.log10(list(mat_s.summed_bp_overlaps_pvalue))))
mat_s.columns = ['Feature', 'log2_FC', 'pvalue', 'minus_log10_pvalue']
mat_s = mat_s.assign(Statistic=['S'] * mat_s.shape[0])
df_volc = mat_n.append(mat_s)
p = ggplot(data=df_volc, mapping=aes(x='log2_FC', y='minus_log10_pvalue'))
p += geom_vline(xintercept=0, color='darkgray')
p += geom_label(aes(label='Feature', fill='Statistic'),
size=5,
color='black',
alpha=.5,
label_size=0)
p += ylab('-log10(pvalue)') + xlab('log2(FC)')
p += ggtitle('Volcano plot (for both N and S statistics)')
p += scale_fill_manual(values={'N': '#7570b3', 'S': '#e7298a'})
p += theme_bw()
return p
def bsuite_bar_plot(df_in: pd.DataFrame,
sweep_vars: Sequence[Text] = None) -> gg.ggplot:
"""Output bar plot of bsuite data."""
df = _clean_bar_plot_data(df_in, sweep_vars)
p = (gg.ggplot(df)
+ gg.aes(x='env', y='score', colour='type', fill='type')
+ gg.geom_bar(position='dodge', stat='identity')
+ gg.geom_hline(yintercept=1., linetype='dashed', alpha=0.5)
+ gg.scale_colour_manual(plotting.CATEGORICAL_COLOURS)
+ gg.scale_fill_manual(plotting.CATEGORICAL_COLOURS)
+ gg.xlab('experiment')
+ gg.theme(axis_text_x=gg.element_text(angle=25, hjust=1))
)
if not all(df.finished): # add a layer of alpha for unfinished jobs
p += gg.aes(alpha='finished')
p += gg.scale_alpha_discrete([0.3, 1.0])
# Compute the necessary size of the plot
if sweep_vars:
p += gg.facet_wrap(sweep_vars, labeller='label_both', ncol=1)
n_hypers = df[sweep_vars].drop_duplicates().shape[0]
else:
n_hypers = 1
return p + gg.theme(figure_size=(14, 3 * n_hypers + 1))
if fc[i] > 1: signif_color[i] = '#3c9040'
text = text.apply(format_pvalue)
text_pos = (maximum + 0.05 * max(maximum)).append(na_series)
text_pos.index = range(len(text_pos))
if display_fit_quality:
fit_qual_text = dm[statname + '_negbinom_fit_quality'].append(na_series)
fit_qual_text.index = range(len(fit_qual_text))
text_with_fit = list()
for t, f in zip(text.tolist(), fit_qual_text.tolist()):
text_with_fit += [t + "\n" + 'fit={0:.2g}'.format(f)]
text = pd.Series(text_with_fit)
aes_plot = aes(x='Feature', y=text_pos, label=text)
p += geom_label(mapping=aes_plot, stat='identity',
size=5, boxstyle='round', label_size=0.2,
color='white', fill=signif_color)
# Theme
p += theme(legend_title=element_blank(),
legend_position="top",
legend_box_spacing=0.65,
legend_key_size=8,
legend_text=element_text(size=8),
legend_key=element_blank(),
axis_title_x=element_blank(),
axis_title_y=element_text(colour='#333333',
size=8,
hjust=4,
angle=90,
def create_readme_image():
kwargs = dict(width=6, height=4)
df = pd.DataFrame({'x': np.linspace(0, 2*np.pi, 500)})
p = (df
>> define(y='np.sin(x)')
>> define_where('y>=0', sign=('"positive"', '"negative"'))
>> (ggplot(aes('x', 'y'))
+ geom_line(aes(color='sign'), size=1.5))
)
p.save('readme-image.png', **kwargs)
+ aes(x='depth', y='y', color='dataset')
+ facet_wrap('metric', scales='free_y', nrow=2, labeller=label_facet)
+ geom_line() + geom_point()
+ xlab('Parse Truncation Depth') + ylab('')
+ scale_color_discrete(name='Dataset')
+ scale_y_continuous(labels=label_y)
+ scale_x_continuous(
breaks=list(range(1, 11)),
minor_breaks=list(range(1, 11)),
limits=[1, 10])
+ theme_fs()
)
p.save(path.join(output_path, 'syn_div_plot.pdf'))
p = (
ggplot(parse_df)
+ aes(x='depth', y='unique_parses', color='dataset')
+ geom_line() + geom_point()
+ xlab('Parse Truncation Depth')
+ ylab('Count of Unique Parses')
+ scale_color_discrete(name='Dataset')
+ scale_x_continuous(
breaks=list(range(1, 11)),
minor_breaks=list(range(1, 11)),
limits=[1, 10])
+ theme_fs()
)
p.save(path.join(output_path, 'n_unique_parses.pdf'))
p = (
ggplot(parse_df)
+ aes(x='depth', y='parse_ratio', color='dataset')
+ geom_line() + geom_point()
+ xlab('Parse Truncation Depth')
def _bar_plot_compare(df: pd.DataFrame) -> gg.ggplot:
"""Bar plot of buite score data, comparing agents on each experiment."""
p = (gg.ggplot(df)
+ gg.aes(x='agent', y='score', colour='agent', fill='agent')
+ gg.geom_bar(position='dodge', stat='identity')
+ gg.geom_hline(yintercept=1., linetype='dashed', alpha=0.5)
+ gg.theme(axis_text_x=gg.element_text(angle=25, hjust=1))
+ gg.scale_colour_manual(plotting.CATEGORICAL_COLOURS)
+ gg.scale_fill_manual(plotting.CATEGORICAL_COLOURS)
)
if not all(df.finished): # add a layer of alpha for unfinished jobs
p += gg.aes(alpha='finished')
p += gg.scale_alpha_discrete([0.3, 1.0])
return p
def plot_learning(df: pd.DataFrame,
sweep_vars: Sequence[Text] = None,
group_col: Text = 'noise_scale') -> gg.ggplot:
"""Plots the average regret through time."""
p = plotting.plot_regret_learning(
df_in=df, group_col=group_col, sweep_vars=sweep_vars,
max_episode=sweep.NUM_EPISODES)
p += gg.geom_hline(gg.aes(yintercept=mnist_analysis.BASE_REGRET),
linetype='dashed', alpha=0.4, size=1.75)
return p