getdist
getdist copied to clipboard
Error when plotting MCSamples with non-nested list of parameters
Hi all,
I've had a long-standing issue with getdist, and the release of v1.0 seems like a good time to point it out : say I have two MCSamples instances, one with parameters "x0" and "x1", and the other with parameters "x1" and "x2". Trying to produce a triangle plot that contains "x0", "x1" and "x2" yields an error mentioning a missing parameter in one of the two MCSamples. Essentially, you're forced to plot only common parameters between the two chains.
See example below :
import numpy as np
from getdist import plots, MCSamples
nsamp = 10000
samps = np.random.multivariate_normal([0, 0], np.eye(2), size=nsamp)
samps2 = np.random.multivariate_normal([0, 0], np.eye(2), size=nsamp)
names = ["x0", "x1"]
samples = MCSamples(samples=samps,names = names)
names = ["x1", "x2"]
samples2 = MCSamples(samples=samps2,names = names)
g = plots.get_subplot_plotter()
g.triangle_plot([samples, samples2], ["x0","x1","x2"] filled=True)
which yields : "Exception: parameter name not found: x2"
Does this all sounds like a feature that should be implemented ? In the past, I managed to do a quite "dirty" modification of getdist in order to be able to do such plot, but I suspect that developers more experienced than me could do a much better job.
I can see there may be cases where it would be useful. Will be a slightly fiddly change everywhere (would ideally also update the GUI code to show all parameters in any chains, rather than just the first chain, but could also just be supported in script). For consistency it should also be allowed for other commands generating more than one subplot.
It shouldn't be too hard to modify get_param_array to take an array of roots and take the first one with a match if needed. Then need to check line colors etc consistent and bounds etc initialized from the first root with a parameter match. I'd certainly welcome a pull request that implements it (I can help tidy it up if needed)
Thanks for your reply Antony ; I would be interested in giving it a try, but I can't guarantee a lot of free time before the end of the year... Will keep you updated !
See that the solution provided in #116 works perfectly for your case now. Replace the plot.py file with the new plot.py in your getdist and it will work normally : https://github.com/cmbant/getdist/blob/4685e549142edebfd210174648da5a97d309b056/getdist/plots.py
Att J.
Thank you for pointing it out, @JaelssonLima !