Customize posterior plot style using plot_posterior

Hi.
I have a question regarding the customization of plot_posterior.
In case of customizing traceplot, we can make a fig and axes handles using subplot function first, and then specifying axes handle in traceplot works perfectly.

For example:

[fig, axes] = plt.subplots(3, 2)
pm.traceplot(trace1, ax=axes, varnames=None)

However, in case of plot_posterior, the same way doesn’t work.

[fig, axes] = plt.subplots(2, 2) 
pm.plot_posterior(trace1, ax=axes)
     
AttributeError: 'numpy.ndarray' object has no attribute 'plot' 

I don’t know why this error is occurring.

As an alternative, I already knew that I can customize the plot from the scratch using axes handle of plot_posterior, for example,

axes = pm.plot_posterior(trace1)

but I’d like to use the ax=axes argument in plot_posterior because it is less cumbersome.

Is there anybody know how to fix this error?
Thank you in advance.

@aloctavodia, @colcarroll I think this plot in arviz is updated right?

Right @junpenglao. This works with ArviZ.

2 Likes

Just for completeness,

pip install arviz

or for the latest version

pip install git+git://github.com/arviz-devs/arviz.git

I’m playing with some stylesheets here, but the layout should look the same. Note that you will need to shape the axes correctly or funny business will happen! You can replace az.load_arviz_data(...) with a pymc3 trace, and it should do fine.

image

1 Like

Thank you very much for your answers @junpenglao @aloctavodia @colcarroll.
However, because traceplot works perfectly with a predefined subplot object using matplotlib, I don’t understand why arviz is required to customize the plot_posterior.

That’s a good and fair question!

  • Architecturally, we are planning to replace all of pymc3’s plotting with arviz for the next release, so most improvements from maintainers have been focused there trying to get to feature parity.
  • We aren’t against maintaining pymc3’s plotting library: If you want to put together a pull request that accepts an axes object there, it would be happily accepted.

I would guess that by the end of January, arviz is integrated with the master branch of PyMC3 on github, depending on how much time everyone has.

1 Like