Plots from Multidimensional Data

The dantro plotting framework tries to make the plotting of multidimensional data as easy as possible. This page describes how to define plot functions and plot configurations for these scenarios.

If you have not already done so, make sure to read up on the corresponding nomenclature (universes and multiverses, introduced here) before continuing on this page.


Plots from Universe Data

To create plots that use data from a single universe, use the UniversePlotCreator. It allows to specify a set of universes to create plots for and provides the plotting function with data from the selected universes.

The plot configuration for a universe plot requires as an additional argument a selection of which universes the plot should be created for. This is done via the universes argument:

---
my_universe_plot:
  universes: all        # can also be:
                        #    1) 'first', 'any'
                        #    2) a dict specifying a multiverse subspace
                        #       to restrict the plots to
                        #    3) a list of (integer) universe IDs
                        #
  # ... more arguments

Without DAG framework

Without the DAG framework, the data needs to be selected manually:

from dantro import DataManager
from dantro.groups import ParamSpaceStateGroup as UniverseGroup
from dantro.plot_creators import (is_plot_func, PlotHelper,
                                  UniversePlotCreator)

@is_plot_func(creator_type=UniversePlotCreator)
def my_plot(dm: DataManager, *, uni: UniverseGroup, hlpr: PlotHelper,
            **additional_kwargs):
    """A universe-specific plot function using the data transformation
    framework and the plot helper framework.

    Args:
        dm: The DataManager, containing *all* data
        uni: The currently selected universe. Select the data from here.
        hlpr: The associated plot helper.
        **additional_kwargs: Anything else from the plot config. Ideally,
            specify these explicitly rather than gathering them via ``**``.
    """
    # Get the data
    x = uni['data/MyModel/foo']
    y = uni['data/MyModel/bar']

    # Plot the data
    hlpr.ax.plot(x, y)

    # Add some information from the universe configuration
    cfg = uni['cfg']
    some_param = cfg['MyModel']['some_param']
    hlpr.provide_defaults('set_title',
                          title="Some Parameter: {}".format(some_param))

    # Done. The plot helper saves the plot.

Note how the data selection is hard-coded in this example. In other words, when not using the data selection and transformation framework, you have to either hard-code the selection or parametrize it, allowing to specify it via the plot configuration arguments.


Plots from Multiverse Data

To create plots that use data from more than one universe — henceforth called multiverse data — use the MultiversePlotCreator. This creator makes it possible to select and combine the data from all selected individual universes and provides the result of the combination to the plot function.

This requires the handling of multidimensional data and depends on the dimensionality of the chosen parameter space. Say the selected data from each universe has dimensionality three and a parameter sweep was done over four dimensions, then the data provided to the plot function has seven dimensions.

Skipping multiverse plots

For skipping MultiversePlotCreator plots, the expected_multiverse_ndim argument can optionally be specified in the plot configuration. The argument specifies a set of dimensionalities with which plotting is possible; if the dimensionality of the associated ParamSpaceGroup is not part of this set, the plot will be skipped.

---
my_plot:
  creator: multiverse

  # Declare that this plot requires a 2-, 3-, or 4-dimensional associated
  # ParamSpaceGroup and should be skipped if this condition is not met
  expected_multiverse_ndim: [2,3,4]

  # ...

See Skipping Plots for general information about skipping of plots.