Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=2, nMCSamples=2)
g = plots.getSinglePlotter(width_inch=4)
g.plot_1d([samples1, samples2], 'x0', marker=0)
.. plot::
:include-source:
from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=2, nMCSamples=2)
g = plots.getSinglePlotter(width_inch=3)
g.plot_1d([samples1, samples2], 'x0', normalized=True, colors=['green','black'])
"""
roots = makeList(roots)
if self.fig is None: self.make_figure()
plotparam = None
plotroot = None
line_args = self._make_line_args(len(roots), **kwargs)
xmin, xmax = None, None
for i, root in enumerate(roots):
root_param = self._check_param(root, param, param_renames)
if not root_param: continue
bounds = self.add_1d(root, root_param, i, normalized=normalized, **line_args[i])
xmin, xmax = self._updateLimit(bounds, (xmin, xmax))
if bounds is not None and not plotparam:
plotparam = root_param
plotroot = root
if plotparam is None: raise GetDistPlotError('No roots have parameter: ' + str(param))
if marker is not None: self.add_x_marker(marker, marker_color)
if 'lims' in kwargs and kwargs['lims'] is not None:
def plots_3d_z(self, roots, param_x, param_y, param_z=None, max_z=None, **kwargs):
"""
Make set of sample scatter subplots of param_x against param_y, each coloured by values of parameters in param_z (all if None).
Any second or more samples in root are shown as contours
:param roots: root name or :class:`~.mcsamples.MCSamples` instance (or list of any of either of these) for the samples to plot
:param param_x: x parameter name
:param param_y: y parameter name
:param param_z: list of parameter to names to color samples in each subplot (default: all)
:param max_z: The maximum number of z parameters we should use.
:param kwargs: keyword arguments for :func:`~GetDistPlotter.plot_3d`
:return: The plot_col, plot_row subplot dimensions of the new figure
"""
roots = makeList(roots)
param_z = self.get_param_array(roots[0], param_z)
if max_z is not None and len(param_z) > max_z: param_z = param_z[:max_z]
param_x, param_y = self.get_param_array(roots[0], [param_x, param_y])
sets = [[param_x, param_y, z] for z in param_z if z != param_x and z != param_y]
return self.plots_3d(roots, sets, **kwargs)
* **alphas**: list of alphas for the different sample contours plotted
* **line_args**: a list of dictionaries with settings for each set of contours
* arguments for :func:`~GetDistPlotter.setAxes`
:return: The xbounds, ybounds of the plot.
.. plot::
:include-source:
from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=4, nMCSamples=2)
g = plots.getSinglePlotter(width_inch = 4)
g.plot_2d([samples1,samples2], 'x1', 'x2', filled=True);
"""
if self.fig is None: self.make_figure()
roots = makeList(roots)
if isinstance(param1, (list, tuple)):
param_pair = param1
param1 = None
param_pair = self.get_param_array(roots[0], param_pair or [param1, param2])
if self.settings.progress: print('plotting: ', [param.name for param in param_pair])
if shaded and not kwargs.get('filled'): self.add_2d_shading(roots[0], param_pair[0], param_pair[1])
xbounds, ybounds = None, None
contour_args = self._make_contour_args(len(roots), **kwargs)
for i, root in enumerate(roots):
if isinstance(root, MixtureND):
res = self.add_2D_mixture_projection(root, param_pair[0], param_pair[1], plotno=line_offset + i,
of=len(roots),
add_legend_proxy=add_legend_proxy and not root in proxy_root_exclude,
**contour_args[i])
else:
res = self.add_2d_contours(root, param_pair[0], param_pair[1], line_offset + i, of=len(roots),
"""
Get :class:`~.paramnames.ParamInfo` for given name for samples with specified root
If a parameter is not found in `root`, returns the original ParamInfo if ParamInfo
was passed, or fails otherwise.
:param root: The root name of the samples
:param param: The parameter name (or :class:`~.paramnames.ParamInfo`)
:param renames: optional dictionary mapping input names and equivalent names
used by the samples
:return: a :class:`~.paramnames.ParamInfo` instance, or None if name not found
"""
if isinstance(param, ParamInfo):
name = param.name
if hasattr(param, 'renames'):
renames = {name: makeList(renames.get(name, [])) + list(param.renames)}
else:
name = param
# NB: If a parameter is not found, errors only if param is a ParamInfo instance
return self.paramNamesForRoot(root).parWithName(
name, error=(name == param), renames=renames)
* **ls** : list of line styles for the different sample contours plotted
* **colors**: list of colors for the different sample contours plotted
* **lws**: list of linewidths for the different sample contours plotted
* **alphas**: list of alphas for the different sample contours plotted
* **line_args**: a list of dict with settings for contours from each root
* arguments for :func:`~GetDistPlotter.add_colorbar`
.. plot::
:include-source:
from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=3, nMCSamples=2)
g = plots.getSinglePlotter(width_inch=4)
g.plot_3d([samples1, samples2], ['x0','x1','x2']);
"""
roots = makeList(roots)
if params_for_plots:
if params is not None: raise GetDistPlotError('plot_3d uses either params OR params_for_plots')
params_for_plots = [self.get_param_array(root, p) for p, root in zip(params_for_plots, roots)]
else:
if not params: raise GetDistPlotError('No parameters for plot_3d!')
params = self.get_param_array(roots[0], params)
params_for_plots = [params for _ in roots] # all the same
if self.fig is None: self.make_figure()
if kwargs.get('filled_compare') is not None:
kwargs = kwargs.copy()
kwargs['filled'] = kwargs['filled_compare']
contour_args = self._make_contour_args(len(roots) - 1, **kwargs)
xlims, ylims = self.add_3d_scatter(roots[0], params_for_plots[0], color_bar=color_bar,
alpha_samples=alpha_samples, **kwargs)
for i, root in enumerate(roots[1:]):
params = params_for_plots[i + 1]
:include-source:
from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=4, nMCSamples=2)
g = plots.getSubplotPlotter()
g.rectangle_plot(['x0','x1'], ['x2','x3'], roots = [samples1, samples2], filled=True)
"""
self.make_figure(nx=len(xparams), ny=len(yparams))
# f, plots = subplots(len(yparams), len(xparams), sharex='col', sharey='row')
sharey = None
yshares = []
xshares = []
ax_arr = []
if plot_roots and yroots or roots and yroots or plot_roots and roots:
raise GetDistPlotError('rectangle plot: must have one of roots, yroots, plot_roots')
if roots: roots = makeList(roots)
limits = dict()
for x, xparam in enumerate(xparams):
sharex = None
if plot_roots:
yroots = plot_roots[x]
elif roots:
yroots = [roots for _ in yparams]
axarray = []
for y, (yparam, subplot_roots) in enumerate(zip(yparams, yroots)):
if x > 0: sharey = yshares[y]
ax = self._subplot(x, y, pars=[xparam, yparam], sharex=sharex, sharey=sharey)
if y == 0:
sharex = ax
xshares.append(ax)
res = self.plot_2d(subplot_roots, param_pair=[xparam, yparam], do_xlabel=y == len(yparams) - 1,
do_ylabel=x == 0, add_legend_proxy=x == 0 and y == 0, **kwargs)