Plotting results

To immediately plot data stored with DACBench wrappers, you can use the built-in plotting functions. They use seaborn and format loaded dataframes automatically (see examples on GitHub).

dacbench.plotting.add_multi_level_ticks(grid: FacetGrid, plot_index: DataFrame, x_column: str, x_label_columns: str) None

Expects a FacedGrid with global_step (x_column) as x-axis and replaces the tick labels to match format episode:step

E.g. Run with 3 episodes, each of 10 steps. This results in 30 global steps. The resulting tick labels could be [‘0’, ‘4’, ‘9’, ‘14’, ‘19’, ‘24’, ‘29’]. After applying this method they will look like [‘0:0’, ‘0:4’, ‘1:0’, ‘1:4’, ‘2:0’, ‘2:4’, ‘3:0’, ‘3:4’]

Parameters
  • grid (sns.FacesGrid) –

  • plot_index (pd.DataFrame) – The mapping between current tick labels (global step values) and new tick labels joined by ‘:’. usually the result from generate_global_step

  • x_column (str) – column label to use for looking up tick values

  • x_label_columns ([str, ...]) – columns labels of columns to use for new labels (joined by ‘:’

dacbench.plotting.generate_global_step(data: DataFrame, x_column: str = 'global_step', x_label_columns: str = ['episode', 'step']) Tuple[DataFrame, str, List[str]]

Add a global_step column which enumerate all step over all episodes.

Returns the altered data, a data frame containing mapping between global_step, x_column and x_label_columns.

Often used in combination with add_multi_level_ticks.

Parameters
  • data

  • x_column (str) – the name of the global_step (default ‘global_step’)

  • x_label_columns ([str, ...]) – the name and hierarchical order of the columns (default [‘episode’, ‘step’]

Returns

Return type

(data, plot_index, x_column, x_label_columns)

dacbench.plotting.plot(plot_function, settings: dict, title: Optional[str] = None, x_label: Optional[str] = None, y_label: Optional[str] = None, **kwargs) FacetGrid

Helper function that: create a FacetGrid 1. Updates settings with kwargs (overwrites values) 2. Plots using plot_function(**settings) 3. Set x and y labels of not provided the columns names will converted to pretty strings using space_sep_upper 4. Sets title (some times has to be readjusted afterwards especially in case of large plots e.g. multiple rows/cols)

Parameters
  • plot_function – function to generate the FacedGrid. E.g. sns.catplot or sns.catplot

  • settings (dict) – a dicts containing all needed default settings.

  • title (str) – Title of the plot (optional)

  • x_label (str) – Label of the x-axis (optional)

  • y_label (str) – Label of the y-axis (optional)

  • kwargs – Keyword arguments to overwrite default settings.

Returns

Return type

sns.FacedGrid

dacbench.plotting.plot_action(data, show_global_step=False, interval=1, title=None, x_label=None, y_label=None, **kargs)

Create a line plot showing actions over time.

Please be aware that action spaces can be quite large and the plots can become quite messy (and take some time) if you try plot all dimensions at once. It is therefore recommended to select a subset of columns before running the plot method.

Per default the mean performance and and one stddev over all instances and seeds is shown if you want to change this specify a property to map those attributes to e.g hue=’seed’ or/and col=’instance’. For more details see: https://seaborn.pydata.org/generated/seaborn.relplot.html

For examples refer to examples/plotting/action_plotting.py

Parameters
  • data (pd.DataFrame) – Dataframe resulting from logging and loading using log2dataframe(logs, wide=True)

  • show_global_step (bool) – If to show the global_step (step enumerated over all episodes) or Episode:Step. (False default)

  • interval (int) – Interval in number of steps to average over. (default = 1)

  • title (str) – Title of the plot (optional)

  • x_label (str) – Label of the x-axis (optional)

  • y_label (str) – Label of the y-axis (optional)

  • kwargs – Keyword arguments to overwrite default settings.

Returns

Return type

sns.FacedGrid

dacbench.plotting.plot_episode_time(data, title=None, x_label=None, y_label=None, **kargs) FacetGrid

Create a line plot showing the measured time per episode.

Per default the mean performance and and one stddev over all instances and seeds is shown if you want to change this specify a property to map those attributes to e.g hue=’seed’ or/and col=’instance’. For more details see: https://seaborn.pydata.org/generated/seaborn.relplot.html

For examples refer to examples/plotting/time_plotting.py

Parameters
  • data (pd.DataFrame) – Dataframe resulting from logging and loading using log2dataframe(logs, wide=True)

  • title (str) – Title of the plot (optional)

  • x_label (str) – Label of the x-axis (optional)

  • y_label (str) – Label of the y-axis (optional)

  • kwargs – Keyword arguments to overwrite default settings.

Returns

Return type

sns.FacedGrid

dacbench.plotting.plot_performance(data, title=None, x_label=None, y_label=None, **kwargs) FacetGrid

Create a line plot of the performance over episodes.

Per default the mean performance and and one stddev over all instances and seeds is shown if you want to change this specify a property to map those attributes to e.g hue=’seed’ or/and col=’instance’. For more details see: https://seaborn.pydata.org/generated/seaborn.relplot.html

For examples refer to examples/plotting/performance_plotting.py

Parameters
  • data (pd.DataFrame) – Dataframe resulting from logging and loading using log2dataframe(logs, wide=True)

  • title (str) – Title of the plot (optional)

  • x_label (str) – Label of the x-axis (optional)

  • y_label (str) – Label of the y-axis (optional)

  • kwargs – Keyword arguments to overwrite default settings.

Returns

Return type

sns.FacedGrid

dacbench.plotting.plot_performance_per_instance(data, title=None, x_label=None, y_label=None, **args) FacetGrid

Create a bar plot of the mean performance per instance ordered by the performance.

Per default the mean performance seeds is shown if you want to change this specify a property to map seed to e.g. col=’seed’. For more details see: https://seaborn.pydata.org/generated/seaborn.catplot.html

For examples refer to examples/plotting/performance_plotting.py

Parameters
  • data (pd.DataFrame) – Dataframe resulting from logging and loading using log2dataframe(logs, wide=True)

  • title (str) – Title of the plot (optional)

  • x_label (str) – Label of the x-axis (optional)

  • y_label (str) – Label of the y-axis (optional)

  • kwargs – Keyword arguments to overwrite default settings.

Returns

Return type

sns.FacedGrid

dacbench.plotting.plot_space(data, space_column_name, show_global_step, interval=1, title=None, x_label=None, y_label=None, **args) FacetGrid

Create a line plot showing sapce over time.

Please be aware that spaces can be quite large and the plots can become quite messy (and take some time) if you try plot all dimensions at once. It is therefore recommended to select a subset of columns before running the plot method. Especially for dict spaces.

Per default the mean performance and and one stddev over all instances and seeds is shown if you want to change this specify a property to map those attributes to e.g hue=’seed’ or/and col=’instance’. For more details see: https://seaborn.pydata.org/generated/seaborn.relplot.html

For examples refer to

examples/plotting/state_plotting.py or examples/plotting/action_plotting.py

Parameters
  • data (pd.DataFrame) – Dataframe resulting from logging and loading using log2dataframe(logs, wide=True)

  • show_global_step (bool) – If to show the global_step (step enumerated over all episodes) or Episode:Step. (False default)

  • interval (int) – Interval in number of steps to average over. (default = 1)

  • title (str) – Title of the plot (optional)

  • x_label (str) – Label of the x-axis (optional)

  • y_label (str) – Label of the y-axis (optional)

  • kwargs – Keyword arguments to overwrite default settings.

Returns

Return type

sns.FacedGrid

dacbench.plotting.plot_state(data, show_global_step=False, interval=1, title=None, x_label=None, y_label=None, **kargs)

Create a line plot showing state over time.

Please be aware that state can be quite large and the plots can become quite messy (and take some time) if you try plot all dimensions at once. It is therefore recommended to select a subset of columns before running the plot method. Especially for dict state spaces.

Per default the mean performance and and one stddev over all instances and seeds is shown if you want to change this specify a property to map those attributes to e.g hue=’seed’ or/and col=’instance’. For more details see: https://seaborn.pydata.org/generated/seaborn.relplot.html

For examples refer to examples/plotting/state_plotting.py

Parameters
  • data (pd.DataFrame) – Dataframe resulting from logging and loading using log2dataframe(logs, wide=True)

  • show_global_step (bool) – If to show the global_step (step enumerated over all episodes) or Episode:Step. (False default)

  • interval (int) – Interval in number of steps to average over. (default = 1)

  • title (str) – Title of the plot (optional)

  • x_label (str) – Label of the x-axis (optional)

  • y_label (str) – Label of the y-axis (optional)

  • kwargs – Keyword arguments to overwrite default settings.

Returns

Return type

sns.FacedGrid

dacbench.plotting.plot_step_time(data, show_global_step=False, interval=1, title=None, x_label=None, y_label=None, **args) FacetGrid

Create a line plot showing the measured time per step.

Per default the mean performance and and one stddev over all instances and seeds is shown if you want to change this specify a property to map those attributes to e.g hue=’seed’ or/and col=’instance’. For more details see: https://seaborn.pydata.org/generated/seaborn.relplot.html

For examples refer to examples/plotting/time_plotting.py

Parameters
  • data (pd.DataFrame) – Dataframe resulting from logging and loading using log2dataframe(logs, wide=True)

  • show_global_step (bool) – If to show the global_step (step enumerated over all episodes) or Episode:Step. (False default)

  • interval (int) – Interval in number of steps to average over. (default = 1)

  • title (str) – Title of the plot (optional)

  • x_label (str) – Label of the x-axis (optional)

  • y_label (str) – Label of the y-axis (optional)

  • kwargs – Keyword arguments to overwrite default settings.

Returns

Return type

sns.FacedGrid

dacbench.plotting.space_sep_upper(column_name: str) str

Separates strings at underscores into headings. Used to generate labels from logging names.

Parameters

column_name (str) –

Returns

Return type

str