How to use the getdist.plots.GetDistPlotError function in getdist

To help you get started, we’ve selected a few getdist examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cmbant / getdist / getdist / plots.py View on Github external
"""
        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:
            xmin, xmax = kwargs['lims']
        else:
            xmin, xmax = self._check_param_ranges(plotroot, plotparam.name, xmin, xmax)
        if normalized:
            mx = plt.gca().yaxis.get_view_interval()[-1]
        else:
            mx = 1.099
        kwargs['lims'] = [xmin, xmax, 0, mx]
        ax = self.setAxes([plotparam], **kwargs)

        if normalized:
            lab = self.settings.norm_prob_label
        else:
            lab = self.settings.prob_label
github cmbant / getdist / getdist / plots.py View on Github external
.. plot::
           :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,
github cmbant / getdist / getdist / plots.py View on Github external
for chain_dir in self.chain_dirs:
                if hasattr(chain_dir, "resolveRoot"):
                    jobItem = chain_dir.resolveRoot(root)
                    if jobItem:
                        file_root = jobItem.chainRoot
                        if hasattr(chain_dir, 'getdist_options'):
                            dist_settings.update(chain_dir.getdist_options)
                        dist_settings.update(jobItem.dist_settings)
                        break
                else:
                    name = os.path.join(chain_dir, root)
                    if os.path.exists(name + '_1.txt') or os.path.exists(name + '.txt'):
                        file_root = name
                        break
        if not file_root:
            raise GetDistPlotError('chain not found: ' + root)
        if not self.chain_settings_have_priority:
            dist_settings.update(self.ini.params)
            if settings: dist_settings.update(settings)
        self.mcsamples[root] = loadMCSamples(file_root, self.ini, jobItem, settings=dist_settings)
        return self.mcsamples[root]
github cmbant / getdist / getdist / plots.py View on Github external
:param plotno: The index of the line added to a plot
        :param kwargs: optional settings to override in the current ones
        :return: The updated dict of arguments.
        """
        if isinstance(self.settings.plot_args, dict):
            args = self.settings.plot_args
        elif isinstance(self.settings.plot_args, list):
            if len(self.settings.plot_args) > plotno:
                args = self.settings.plot_args[plotno]
                if args is None: args = dict()
            else:
                args = {}
        elif not self.settings.plot_args:
            args = dict()
        else:
            raise GetDistPlotError(
                'plot_args must be list of dictionaries or dictionary: %s' % self.settings.plot_args)
        args.update(kwargs)
        return args
github cmbant / getdist / getdist / plots.py View on Github external
g.plots_2d([samples1, samples2], param_pairs=[['x0', 'x1'], ['x1', 'x2']],
                                    nx=2, legend_ncol=2, colors=['blue', 'red'])
        """
        pairs = []
        roots = makeList(roots)
        if isinstance(param1, (list, tuple)) and len(param1) == 2:
            params2 = [param1[1]]
            param1 = param1[0]
        if param_pairs is None:
            if param1 is not None:
                param1 = self._check_param(roots[0], param1)
                params2 = self.get_param_array(roots[0], params2)
                for param in params2:
                    if param.name != param1.name: pairs.append((param1, param))
            else:
                raise GetDistPlotError('No parameter or parameter pairs for 2D plot')
        else:
            for pair in param_pairs:
                pairs.append((self._check_param(roots[0], pair[0]), self._check_param(roots[0], pair[1])))
        if filled and shaded:
            raise GetDistPlotError("Plots cannot be both filled and shaded")
        plot_col, plot_row = self.make_figure(len(pairs), nx=nx)

        for i, pair in enumerate(pairs):
            self._subplot_number(i)
            self.plot_2d(roots, param_pair=pair, filled=filled, shaded=not filled and shaded,
                         add_legend_proxy=i == 0, **kwargs)

        self.finish_plot(self._default_legend_labels(legend_labels, roots), legend_ncol=legend_ncol,
                         label_order=label_order)
        return plot_col, plot_row
github cmbant / getdist / getdist / plots.py View on Github external
* **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]
            res = self.add_2d_contours(root, params[0], params[1], i + line_offset, add_legend_proxy=add_legend_proxy,
                                       zorder=i + 1, **contour_args[i])
github cmbant / getdist / getdist / plots.py View on Github external
def param_latex_label(self, root, name, labelParams=None):
        """
        Returns the latex label for given parameter.

        :param root: root name of the samples having the parameter (or :class:`~.mcsamples.MCSamples` instance)
        :param name:  The param name
        :param labelParams: optional name of .paramnames file to override parameter name labels
        :return: The latex label
        """
        if labelParams is not None:
            p = self.sampleAnalyser.paramsForRoot(root, labelParams=labelParams).parWithName(name)
        else:
            p = self._check_param(root, name)
        if not p: raise GetDistPlotError('Parameter not found: ' + name)
        return p.latexLabel()
github cmbant / getdist / getdist / plots.py View on Github external
* 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]
            res = self.add_2d_contours(root, params[0], params[1], i + line_offset, add_legend_proxy=add_legend_proxy,
                                       zorder=i + 1, **contour_args[i])
            xlims, ylims = self._updateLimits(res, xlims, ylims)
        if not 'lims' in kwargs:
            params = params_for_plots[0]