cmbant/getdist

How to plot two 2d single plotter side by side from two different dataset results ?

Closed this issue · 8 comments

am610 commented

I can plot

g = plots.get_single_plotter() g.plot_2d([samples1, samples2], 'x0', 'x1',filled=True)

But, I have another pair of samples3, samples4 with the same variables x0, x1
I would like to plot them side by side.

How can I do it ?

I can do something like this

g = plots.get_subplot_plotter(subplot_size=2.5)

g.settings.scaling = False # prevent scaling down font sizes even though small subplots

g.plots_2d([samples1, samples2],[samples3, samples4], param_pairs=[['x0', 'x1'], ['x0', 'x1']], nx=2, filled=True);

However this puts the same plot (sample1, sample 2) in both the figures left and right.

You can either make a new figure, or make an array of subplots and pass the ax argument to plot_2d.

I have a similar question as the OP. How do you make an array of subplots in this case?

E.g. pyplot.subplots.

Could you give an example script? I am having trouble figuring out how to pass the ax argument to plot_2d. When I create subplots with pyplot.subplots and then pass ax to plot_2d I get the following error : _ax_width is not a valid attribute for class <class 'getdist.plots.GetDistPlotter'> .

Can you give the code and full trace back please

Of course! The code is:

`fig, (ax1,ax2,ax3) = plt.subplots(3, 1,figsize=(4, 7),sharex=True)

g=plots.get_subplot_plotter()

g.settings.figure_legend_frame = False
g.settings.legend_fontsize=18
g.settings.axes_fontsize=20
g.settings.axes_labelsize = 30

g.plot_2d(chain1, 'param1','param2', filled=False, ax=ax1);
g.plot_2d(chain2, 'param3','param2', filled=False, ax=ax2);
g.plot_2d(chain3, 'param4','param2', filled=False, ax=ax3);`

The full traceback is:

`---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/var/folders/f1/4zl8lk5157v3ztlc4wdmyyg00000gn/T/ipykernel_78396/2686930721.py in
8 g.settings.axes_labelsize = 30
9
---> 10 g.plot_2d(EDE_Full_rsmarg, 'ln10^{10}A_s','f_ede', filled=False, ax=ax1);

~/opt/anaconda3/lib/python3.9/site-packages/getdist/plots.py in plot_2d(self, roots, param1, param2, param_pair, shaded, add_legend_proxy, line_offset, proxy_root_exclude, ax, **kwargs)
1684 contour_args = self._make_contour_args(len(roots), **kwargs)
1685 for i, root in enumerate(roots):
-> 1686 res = self.add_2d_contours(root, param_pair[0], param_pair[1], line_offset + i, of=len(roots), ax=ax,
1687 add_legend_proxy=add_legend_proxy and root not in proxy_root_exclude,
1688 **contour_args[i])

~/opt/anaconda3/lib/python3.9/site-packages/getdist/plots.py in add_2d_contours(self, root, param1, param2, plotno, of, cols, contour_levels, add_legend_proxy, param_pair, density, alpha, ax, **kwargs)
1106 alpha=alpha * self.settings.alpha_factor_contour_lines, **clean_args(kwargs))
1107 else:
-> 1108 args = self._get_line_styles(plotno, **kwargs)
1109 linestyles = [args['ls']]
1110 cols = [args['color']]

~/opt/anaconda3/lib/python3.9/site-packages/getdist/plots.py in _get_line_styles(self, plotno, **kwargs)
839 args['color'] = self._get_default_ls(plotno)[1]
840 if 'lw' not in args:
--> 841 args['lw'] = self._scaled_linewidth(self.settings.linewidth)
842 return args
843

~/opt/anaconda3/lib/python3.9/site-packages/getdist/plots.py in _scaled_linewidth(self, linewidth)
1961
1962 def _scaled_linewidth(self, linewidth):
-> 1963 return self.settings.scaled_linewidth(self._ax_width, linewidth)
1964
1965 def _subplots_adjust(self):

~/opt/anaconda3/lib/python3.9/site-packages/getdist/_base.py in getattribute(self, name)
38 res = _map_name(self, name)
39 if res is None:
---> 40 raise AttributeError('%s is not a valid attribute for class %s' % (name, self.class))
41 value, newname = res
42 if newname is None:

AttributeError: _ax_width is not a valid attribute for class <class 'getdist.plots.GetDistPlotter'>`

I think get_single_plotter will work.

But actually there is a built-in way, e.g.
g.rectangle_plot(['x1','x1'],['x2'],yroots= [samples1,samples2],legend_labels=[]);

rectangle_plot worked perfectly-- thank you!