How to use the plotnine.theme function in plotnine

To help you get started, we’ve selected a few plotnine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deepmind / bsuite / bsuite / experiments / summary_analysis.py View on Github external
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
github dm3ll3n / ezpq / ezpq / Plot.py View on Github external
drop_grid.add('panel_grid_minor_y')
            elif grid_lines == 'minor':
                drop_grid.add('panel_grid_major_y')
        elif grid_axis == 'y':
            drop_grid.update(['panel_grid_major_x', 'panel_grid_minor_x'])
            if grid_lines == 'major':
                drop_grid.add('panel_grid_minor_x')
            elif grid_lines == 'minor':
                drop_grid.add('panel_grid_major_x')

        grid_opt = dict()
        for x in drop_grid:
            grid_opt[x] = gg.element_blank()

        return getattr(gg, 'theme_'+theme)() + \
                gg.theme(panel_border = gg.element_blank(),
                          axis_line = gg.element_line(color = "black"),
                          **grid_opt)
github deepmind / bsuite / bsuite / experiments / summary_analysis.py View on Github external
"""Compare score for just one experiment."""
  if len(summary_df) == 0:  # pylint:disable=g-explicit-length-test
    print('WARNING: you have no bsuite summary data, please reload.')
    return
  env_df = summary_df[summary_df.bsuite_env == bsuite_env]
  if len(env_df) == 0:  # pylint:disable=g-explicit-length-test
    print('Warning, you have no data for bsuite_env={}'.format(bsuite_env))
    print('Your dataframe only includes bsuite_env={}'
          .format(summary_df.bsuite_env.unique()))
    return

  df = _clean_bar_plot_data(env_df, sweep_vars)
  n_agent = len(df.agent.unique())
  p = _bar_plot_compare(df)
  plot_width = min(2 + n_agent, 12)
  p += gg.theme(figure_size=(plot_width, 6))
  p += gg.ggtitle('bsuite score for {} experiment'.format(bsuite_env))
  print('tags={}'.format(df.tags.iloc[0]))
  return p
github dputhier / pygtftk / pygtftk / plugins / ologram.py View on Github external
# -------------------------------------------------------------------------
    # Saving
    # -------------------------------------------------------------------------

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        fxn()

        message("Saving diagram to file : " + pdf_file.name)
        message("Be patient. This may be long for large datasets.")

        # NOTE : We must manually specify figure size with save_as_pdf_pages
        save_as_pdf_pages(filename=pdf_file.name,
                          plots=[p1 + theme(figure_size=figsize),
                                 p2 + theme(figure_size=figsize),
                                 p3 + theme(figure_size=figsize)],
                          width=pdf_width,
                          height=pdf_height)

    gc.disable()
github dputhier / pygtftk / pygtftk / plugins / merge_ologram_stats.py View on Github external
message("Plotting")
    my_plot = ggplot(data=df_merged,
                     mapping=aes(y='Feature', x='dataset'))
    my_plot += geom_tile(aes(fill = 'summed_bp_overlaps_log2_fold_change'))
    my_plot += scale_fill_gradient2()
    my_plot += labs(fill = "log2(fold change) for summed bp overlaps")

    # Points for p-val. Must be after geom_tile()
    my_plot += geom_point(data = df_merged.loc[df_merged['pval_signif']],
        mapping = aes(x='dataset',y='Feature',color = '-log_10(pval)'), size=5, shape ='D', inherit_aes = False)
    my_plot += scale_color_gradientn(colors = ["#160E00","#FFB025","#FFE7BD"])
    my_plot += labs(color = "-log10(p-value)")

    # Theming
    my_plot += theme_bw()
    my_plot += theme(panel_grid_major=element_blank(),
                     axis_text_x=element_text(rotation=90),
                     panel_border=element_blank(),
                     axis_ticks=element_blank())

    # -------------------------------------------------------------------------
    # Saving
    # -------------------------------------------------------------------------

    message("Saving")
    nb_ft = len(list(df_merged['Feature'].unique()))
    nb_datasets = len(list(df_merged['dataset'].unique()))

    if pdf_width is None:
        panel_width = 0.6
        pdf_width = panel_width * nb_datasets
github iosband / ts_tutorial / src / base / plot.py View on Github external
'Ensemble 100', 'Ensemble 300']
      gg_legend = gg.scale_colour_manual(values=custom_colors,
                                         labels=custom_labels,
                                         name='agent')
    else:
      gg_legend = gg.scale_colour_manual(custom_colors, name='agent')

    p = (gg.ggplot(df_family)
         + gg.aes('t', 'instant_regret', colour='agent_name')
         + gg.geom_line(size=1.25, alpha=0.75)
         + gg.facet_wrap('~ agent_family')
         + gg_legend
         + gg.coord_cartesian(ylim=(0, 60))
         + gg.xlab('time period (t)')
         + gg.ylab('per-period regret')
         + gg.theme(figure_size=(6, 6)))
    plot_dict[experiment_name + '_' + agent_family] = p

  return plot_dict
github TyberiusPrime / pyggplot / pyggplot / plot_nine.py View on Github external
def facet(self, *args, **kwargs):
        """Compability to old calling style"""
        if 'free_y' in kwargs['scales']:
            self.plot += p9.theme(subplots_adjust={'wspace':0.2})
        return self.facet_wrap(*args, **kwargs)
github Pinafore / qb / qanta / buzzer / plot.py View on Github external
df = df.append(df_thr, ignore_index=True)

    outcome_type = CategoricalDtype(categories=[15, 10, 5, 0, -5, -10, -15])
    df['Outcome'] = df['Outcome'].astype(outcome_type)
    model_type = CategoricalDtype(
        categories=['Threshold', 'MLP', 'RNN'])
    df['Model'] = df['Model'].astype(model_type)

    p = (
        ggplot(df)
        + geom_col(aes(x='Possibility', y='Count', fill='Outcome'),
                   width=0.7)
        + facet_grid('Model ~')
        + coord_flip()
        + theme_fs()
        + theme(aspect_ratio=0.17)
        + scale_fill_brewer(type='div', palette=7)
    )

    figure_dir = os.path.join('output/buzzer/{}_protobowl.pdf'.format(fold))
    p.save(figure_dir)
github Pinafore / qb / jmlr.py View on Github external
def __init__(self, base_size=11, base_family='DejaVu Sans'):
        theme_light.__init__(self, base_size, base_family)
        self.add_theme(theme(
            axis_ticks=element_line(color='#DDDDDD', size=0.5),
            panel_border=element_rect(fill='None', color='#838383',
                                      size=1),
            strip_background=element_rect(
                fill='#DDDDDD', color='#838383', size=1),
            strip_text_x=element_text(color='black'),
            strip_text_y=element_text(color='black', angle=-90),
            legend_key=element_blank()
        ), inplace=True)
github dputhier / pygtftk / pygtftk / plugins / profile.py View on Github external
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)

    # -------------------------------------------------------------------------
    #
    # Theming
    #
    # -------------------------------------------------------------------------

    message("Theming and ordering. Please be patient...")
    p += theme(legend_title=element_blank())
    theme_plotnine_fun = getattr(plotnine, theme_plotnine)
    p += theme_plotnine_fun()

    # remove major/minor grid due to
    # weird placements by default
    # in this plotnine version

    p += theme(legend_position="top",
               legend_title=element_blank(),
               legend_key=element_rect(colour="white", fill="white"),
               legend_text=element_text(size=8),
               axis_text_x=element_text(size=axis_text, angle=40, hjust=1.5),
               axis_text_y=element_text(size=axis_text),
               axis_ticks=element_line(colour=border_color),
               axis_line=element_line(colour=border_color, size=1),
               axis_line_y=element_line(colour=border_color, size=1),