コード例 #1
0
    def corner(**kwargs):
        """
        Evaluate mcmc corner plot.

        """
        flat_chain = kwargs.pop('flat_chain')
        fit_params = kwargs.pop('fit_params')
        variable_labels = kwargs.pop('variable_labels')
        figure = _corner(flat_chain, **kwargs)

        # Extract the axes
        ndim = flat_chain.shape[1]
        axes = np.array(figure.axes).reshape((ndim, ndim))

        # Loop over the diagonal, adding units
        for i, label in enumerate(variable_labels):
            ax = axes[i, i]
            value = fit_params[label]['value']
            bottom = fit_params[label]["confidence_interval"]['min'] - value
            top = fit_params[label]["confidence_interval"]['max'] - value

            unit = fit_params[label]['unit']
            unit = '' if unit == 'dimensionless' or unit is None else unit
            title = r'{0}=${1:.2f}^{{{2:+.2f}}}_{{{3:+.2f}}}$ {4}'.format(
                kwargs['labels'][i], value, top, bottom, unit)
            ax.set_title(title)

        plt.show()
コード例 #2
0
def corner(*args, **kwargs):
    """
    Override `corner.corner` by making some appearance tweaks.

    """
    # Get the usual corner plot
    figure = _corner(*args, **kwargs)

    # Get the axes
    ndim = int(np.sqrt(len(figure.axes)))
    axes = np.array(figure.axes).reshape((ndim, ndim))

    # Smaller tick labels
    for ax in axes[1:, 0]:
        for tick in ax.yaxis.get_major_ticks():
            tick.label.set_fontsize(10)
        formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
        ax.yaxis.set_major_formatter(formatter)
        ax.set_ylabel(
            ax.get_ylabel(), fontsize=kwargs.get("corner_label_size", 16)
        )
    for ax in axes[-1, :]:
        for tick in ax.xaxis.get_major_ticks():
            tick.label.set_fontsize(10)
        formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
        ax.xaxis.set_major_formatter(formatter)
        ax.set_xlabel(
            ax.get_xlabel(), fontsize=kwargs.get("corner_label_size", 16)
        )

    # Pad the axes to always include the truths
    truths = kwargs.get("truths", None)
    if truths is not None:
        for row in range(1, ndim):
            for col in range(row):
                lo, hi = np.array(axes[row, col].get_xlim())
                if truths[col] < lo:
                    lo = truths[col] - 0.1 * (hi - truths[col])
                    axes[row, col].set_xlim(lo, hi)
                    axes[col, col].set_xlim(lo, hi)
                elif truths[col] > hi:
                    hi = truths[col] - 0.1 * (hi - truths[col])
                    axes[row, col].set_xlim(lo, hi)
                    axes[col, col].set_xlim(lo, hi)

                lo, hi = np.array(axes[row, col].get_ylim())
                if truths[row] < lo:
                    lo = truths[row] - 0.1 * (hi - truths[row])
                    axes[row, col].set_ylim(lo, hi)
                    axes[row, row].set_xlim(lo, hi)
                elif truths[row] > hi:
                    hi = truths[row] - 0.1 * (hi - truths[row])
                    axes[row, col].set_ylim(lo, hi)
                    axes[row, row].set_xlim(lo, hi)

    return figure
コード例 #3
0
def plot_mcmc_results(sampled_mcmc, bins=20, smooth=None, truths=None):
    """
    Uses the 'corner' package to make a *sick* corner plot showing the
    projections of the parameters from this MCMC run in a multidimensional
    space.

    sampled_mcmc: The output of a pymc run.
    bins: The number of bins in the histogram.
    smooth: Higher number = more smooth (for the 2D plots).
    truths: List in [x, spec_index, y] order of known parameter values if applicable.
    """
    x_results = sampled_mcmc.x.trace()
    y_results = sampled_mcmc.y.trace()
    spec_index_results = sampled_mcmc.spec_index.trace()

    mcmc_all_results = _np.array([x_results, spec_index_results, y_results]).T
    corner_plot = _corner(mcmc_all_results, labels=["x", "spectral index", "y"], bins=bins, smooth=smooth, truths=truths)
    
    return corner_plot
コード例 #4
0
def corner(*args, **kwargs):
    if _corner is None:
        raise ImportError('could not import corner')
    return _corner(*args, **kwargs)