Skip to content

Note

Click here to download the full example code

Introduction to Summaries

When you have a few chains and want to contrast them all with each other, you probably want a summary plot.

To show you how they work, let's make some sample data that all has the same average.

from chainconsumer import Chain, ChainConfig, ChainConsumer, PlotConfig, Truth, make_sample

# Here's what you might start with
df_1 = make_sample(num_dimensions=4, seed=1)
df_2 = make_sample(num_dimensions=5, seed=2)
print(df_1.head())

Out:

          A         B          C          D  log_posterior
0  0.435628  4.964093   9.072183  16.094515      -2.561876
1  1.466833  3.831407   8.764188  16.317087      -3.354758
2 -1.324936  4.993989  10.480634  14.350524      -3.832495
3  1.140176  3.857557   9.114561  15.400507      -3.077645
4 -0.768539  6.433234  10.694261  14.268826      -3.350615

Using distributions

# And now we give this to chainconsumer
c = ChainConsumer()
c.add_chain(Chain(samples=df_1, name="An Example Contour"))
c.add_chain(Chain(samples=df_2, name="A Different Contour"))
fig = c.plotter.plot_summary()

A, B, C, D, E

Using Errorbars

Note that because the errorbar kwarg is specific to this function it is not part of the PlotConfig class.

fig = c.plotter.plot_summary(errorbar=True)

A, B, C, D, E

The other features of ChainConsumer should work with summaries too.

For example, truth values should work just fine.

c.add_truth(Truth(location={"A": 0, "B": 1}, line_style=":", color="red"))
fig = c.plotter.plot_summary(errorbar=True, vertical_spacing_ratio=2.0)

A, B, C, D, E

And similarly, our overrides are generic and so effect this method too.

c.set_override(ChainConfig(bar_shade=False))
c.set_plot_config(PlotConfig(watermark="Preliminary", blind=["E"]))
fig = c.plotter.plot_summary()

A, B, C, D, E

Total running time of the script: ( 0 minutes 4.328 seconds)

Download Python source code: plot_1_summary.py

Download Jupyter notebook: plot_1_summary.ipynb

Gallery generated by mkdocs-gallery