Skip to content

General tidy and refactor of plot_corner

Gregory Ashton requested to merge clean-up-corner-plot into master

In addition to a general tidy up of plot_corner (adding some comments and reordering things for clarity), this introduces the following four options to plots truths:

#  The recommended (and documented) way
>>> result.plot_corner(parameters=dict(mu=2, sigma=5))

#  The way it was done in the past (backward compatible, but undocumented)
>>> result.plot_corner(truths=dict(mu=2, sigma=5))

#  As separate lists
>>> result.plot_corner(parameters=['mu', 'sigma'], truths=[2, 5])

#  Don't plot truths, just give the order/which to plot
>>> result.plot_corner(parameters=['mu', 'sigma'])

Meanwhile, giving anything but a list for parameters and truths will raise an error

#  This will raise a `ValueError`
>>> result.plot_corner(parameters=dict(mu=2, sigma=5), truths=dict(mu=2, sigma=5))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-43f821651b7e> in <module>()
----> 1 result.plot_corner(parameters=['mu', 'sigma'], truths=dict(mu=1, sigma=2))

/home/user1/tupak/tupak/core/result.py in plot_corner(self, parameters, priors, titles, save, filename, dpi, **kwargs)
    357             else:
    358                 raise ValueError(
--> 359                     "Combination of parameters and truths not understood")
    360 
    361         # If parameters is a dictionary, use the keys to determine which

ValueError: Combination of parameters and truths not understood

#  This will also raise an error indicating that the lengths are mismatched
>>> result.plot_corner(parameters=['mu', 'sigma'], truths=[2, 5, 4])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-ba912057ec35> in <module>()
----> 1 result.plot_corner(parameters=['mu', 'sigma'], truths=[2, 5, 5])

/home/user1/tupak/tupak/core/result.py in plot_corner(self, parameters, priors, titles, save, filename, dpi, **kwargs)
    352                 if len(parameters) != len(truths):
    353                     raise ValueError(
--> 354                         "Length of parameters and truths don't match")
    355             elif isinstance(truths, dict) and parameters is None:
    356                 parameters = kwargs.pop('truths')

ValueError: Length of parameters and truths don't match
Edited by Gregory Ashton

Merge request reports

Loading