Plotting subspaces#

Summary

On this page, you will see how to

  • use the subspace key to select only certain parts of the parameter space for plotting

  • use col_wrap: auto when plotting facet_grid panels to automatically square a plot with many columns and few rows.

For large parameter sweeps across many dimensions, you may often wish to only select a subspace of the whole parameter space for plotting. This is easily achieved using the subspace key. Subspace selection will also improve performance speeds, since less data is being loaded into memory.

Consider the facet grid example we considered in a previous section. Here, we performed a parameter sweep across three dimensions (seed, transmission rate, immunity rate) and plotted the resulting curves of the susceptible, infected, and recovered populations:

A facet grid example

If we want to restrict ourselves to the subspace of transmission rate = 0.2 and immunity rate < 0.3, we can do the following:

infection_curves_averaged:

  # Same as before
  based_on:
    - .creator.multiverse
    - .plot.facet_grid.errorbands

  select_and_combine:
    fields:
      infected:
        path: densities
        transform:
          - .sel: [!dag_prev , { kind: [infected] }]

    # Add the following entry:
    subspace:
      transmission rate: [0.2]
      immunity rate: [0, 0.1, 0.2]

  transform:
    - # same as before ...

  x: time
  y: infected density
  yerr: yerr
  col: immunity rate
  hue: kind

Note that we are no longer assigning the row key, as there is only a single row to plot! The subspace selection led to a dimensionality reduction.

The output then looks like this:

A facet grid example with subspace selection

Note

Even when selecting a single value, the subspace entry needs to be sequence-like, i.e. a list. That’s why we specify transmission rate: [0.2] above.

Subspace selection happens via the ParamSpace method activate_subspace(), which also offers some other syntax options.

Hint

If you have lots of columns and few rows, use col_wrap: auto to create a more square plot.