Author(s) Paul Miles | August 7, 2018
This tutorial provides a demonstration of the joint distributions plotting routine available in mcmcplot
.
# import required packages
import numpy as np
from mcmcplot import mcseaborn as mcs
import warnings
warnings.filterwarnings("ignore")
The plotting routines are designed to be used in conjunction with the result of a MCMC simulation. For the purpose of this example, we consider a randomly generated chain. We will consider a chain with 3 parameters that have the following distributions:
nsimu = 1000
npar = 3
mu = np.array([1.0, 2.5, -1.3])
sig = np.array([0.5, 3.0, 0.75])
chain = np.zeros([nsimu, npar])
for ii in range(npar):
chain[:,ii] = sig[ii]*np.random.randn(nsimu,) + mu[ii]
This routine will generate a joint distribution plot for each parameter combination in the chain. For this example, npar = 3
, so 3 different plots will be generated representing the combinations:
Note, that each function call returns the figure handles as well as the settings used to generate the plots.
fjd, used_settings = mcs.plot_joint_distributions(chains = chain, settings = None)
We can easily adjust the type of joint plot, size of the figure, and color map defining the following settings.
settings = {'jointplot': {'kind': 'hex', 'height': 4, 'color': 'g'}}
fjd, used_settings = mcs.plot_joint_distributions(chains = chain[:,0:2], settings = settings)
settings = {'jointplot': {'kind': 'reg', 'height': 6, 'color': 'b'}}
fjd, used_settings = mcs.plot_joint_distributions(chains = chain[:,0:2], settings = settings)
The default seaborn style is white
, but it can be changed by defining the sns_style
variable. Each style has it's own settings, so see the seaborn style documentation for details.
settings = {'jointplot': {'kind': 'scatter', 'height': 4, 'color': 'k'}}
fjd, used_settings = mcs.plot_joint_distributions(chains = chain[:,0:2], sns_style='dark', settings = settings)
settings = {'sns': {'figure.facecolor': 'yellow'}}
fjd, used_settings = mcs.plot_joint_distributions(chains = chain[:,0:2], settings = settings)
As seaborn is built on top of matplotlib, you can edit various plot features in the same way. The output from the plot_joint_distributions
method will contain the figure handles inside a list
.
fjd, used_settings = mcs.plot_joint_distributions(chains = chain[:,0:2], settings = None)
a = fjd[0].ax_joint;
a.set_xticklabels(a.get_xticklabels(), fontsize = 22);
a.set_yticklabels(a.get_yticklabels(), fontsize = 22);
a.set_xlabel(a.get_xlabel(), fontsize = 22);
a.set_ylabel(a.get_ylabel(), fontsize = 22);
f = fjd[0]
f.savefig('basic_joint_distributions.png')