question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plot multiple coordinates of a posterior variable's dimension on the same axis

See original GitHub issue

Tell us about it

I think it should be possible with Arviz to plot multiple coordinates of a posterior variable on the same graph, for simple comparison. I have not seen an example that achieves this.

Basically, I would like to create select plots from az.plot_trace() for select variables/coords/dims, without the actual traces, etc:

import arviz as az
import matplotlib.pyplot as plt

data = az.load_arviz_data('non_centered_eight')

coords = {'school': ['Choate', 'Lawrenceville']}

az.plot_trace(data,
              var_names=('theta'),
              coords=coords,
              combined=True,
              divergences=False,
             )

image

To create the same plot myself of theta I can run:

az.plot_dist(data.posterior.sel(school='Choate')["theta"], color='C0', label='school: Choate')
az.plot_dist(data.posterior.sel(school='Lawrenceville')["theta"], color='C1', label='school: Lawrenceville')
plt.ylabel('Density')
plt.title('theta')
plt.legend(frameon=False)

image

I imagine a function that takes a list of variables (one variable per axis), and the coords to plot separately per variable.

az.plot_posterior_comparison(data,var_names=["theta"], coords= {'school': ['Choate', 'Lawrenceville']})
az.plot_posterior_comparison(data,var_names=["theta", "mu"], coords= {'school': ['Choate', 'Lawrenceville']})

I’m not looking for all the stats found on plot_posterior() or the ridge plot aspect of plot_forest. I’m aware of plot_dist_comparison but I think that is for comparing the prior and posterior. The name of that function might have made sense for this use.

❗ As an aside, I was surprised that dist_plot is set to color=C0 by default instead of using the matplotlib color cycle.

Thoughts on implementation

I’m not sure if this should be a standalone function, or an expanded version of dist_plot.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
aloctavodiacommented, Oct 29, 2021
0reactions
OriolAbrilcommented, Nov 1, 2021

We could have a compact argument but we’d have to be careful and see how it can be integrated with #1676 so that it handles multidimensional case gracefully.

i.e. for a 3d (in addition to chain and draw dims) do we want to compact like we do in plot_trace? or, given subject, treatment, repetition do we maybe want to “skip” repetition and “compact” subject so we see a subplot per treatment, each of them having n kdes, one per subject so we can easily compare how each subject is affected by the same treatment?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Combining dimensions in Arviz plots - PyMC Discourse
I have a distribution that has a large dimension to the observed variable, obs. This large dimension, "rows", corresponds to different ...
Read more >
How to pass coordinates to arviz / pymc3 function ...
I'm doing some Bayesian modelling in pymc3 and would like to plot the posterior distribution using plot_posterior (which comes from the arviz ...
Read more >
Label guide — ArviZ 0.14.0 documentation
Through label based indexing, you can use labels to plot a subset of selected variables. Example: Label based indexing#. For a case where...
Read more >
Coordinates and Dimensions of ECCOv4 NetCDF files
dimensions, respectively. The c-grid vertical coordinates¶. In the horizontal, variables can take one of two locations: c and w ...
Read more >
Parallel coordinates plot of MCMC draws - Stan
Parallel coordinates plot of MCMC draws. There is one dimension per parameter along the horizontal axis and each set of connected line segments...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found