Histograms#

Summary

On this page, you will see how to

  • use .plot.facet_grid.hist to plot histograms

  • use .plot.facet_grid.hist to plot panels of histograms

WIP 🚧

  • Plotting several panels of histograms with .plot.facet_grid.hist does not yet work.

Histograms are one of the most commonly used plots to visualise distributions. Let us run the SEIRD model with a fixed configuration multiple times over different seeds, and plot a histogram of the maximum peak height of the number of infected agents.

To plot a histogram, base your plot on .plot.facet_grid.hist. We can use the np.max operation in the data transformation process to select the maximum density for each run:

histogram:
  based_on:
    - .creator.multiverse
    - .plot.facet_grid.hist

  # Select only the infected population
  select_and_combine:
    fields:
      infected:
        path: densities
        transform:
          - .sel: [!dag_prev , { kind: [infected] }]

  # Get the maximum value
  transform:
    - np.max: [!dag_tag infected]
      kwargs:
        axis: 3
      tag: data

  # Helpers
  helpers:
    set_title:
      title: Maximum density of infected agents
    set_labels:
      x: Peak height
      y: ' '

Any additional entries are keyword arguments that will be passed to the low-level plotting function, in this case matplotlib.pyplot.hist. For example, we can specify the number of bins and color by adding

histogram:

  # all the previous entries ...

  color: mediumseagreen
  bins: 50

The output will look something like this:

caption