Skip to content

pairplot: documentation, more options and tutorial #961

Closed

Description

@janfb

The pairplot function is our main function for visualizing posteriors.

def pairplot(

It would be great to improve it bit:

  • adding more documentation
  • defaults that produce a decent default figure, even when plotting several distributions, e.g., prior vs posterior
  • more options, see

    sbi/sbi/analysis/plot.py

    Lines 328 to 330 in c3c2b6e

    # TODO: add color map support
    # TODO: automatically determine good bin sizes for histograms
    # TODO: add legend (if legend is True)

    (use bins="auto" as default)
  • a tutorial on how to use all the options 🥇

Activity

  1. added
    docs
    beginner friendly
    hackathon
    on Feb 28, 2024
  2. added this to the Hackathon 2024 milestone on Feb 28, 2024
  3. added
    karma
    on Feb 28, 2024
  4. famura commented on Mar 13, 2024

    @famura
    Collaborator

    I plan to have a look at it during the hackathon

  5. Matthijspals commented on Mar 13, 2024

    @Matthijspals
    Collaborator

    Also happy to help out here during the hackathon!

  6. Ziaeemehr commented on Mar 19, 2024

    @Ziaeemehr
    Contributor

    It would be nice to have joint_plot for arbitrary pair of parameters:

    def plot_joint(x, limits, ax, cmap="hot", label=None, points=[],
                   xlabel="", ylabel="", add_corr=True):
        '''
        plot joint distribution of given samples
        
        Parameters
        ----------
        x : 2d-array
            samples from the distribution
        limits : list of tuples
            limits of the distribution
        '''
        
        density = gaussian_kde(x[:, [1, 0]].T, bw_method='scott')
        col = 1
        row = 0
        X, Y = np.meshgrid(
            np.linspace(limits[col][0], limits[col][1], 50,),
            np.linspace(limits[row][0], limits[row][1], 50))
        positions = np.vstack([X.ravel(), Y.ravel()])
        Z = np.reshape(density(positions).T, X.shape)
        # normalize Z
        Z = Z / np.max(Z)
        im = ax.imshow(Z, cmap=cmap,
                  extent=(limits[col][0], limits[col][1],
                          limits[row][0], limits[row][1]),
                        origin="lower",
                        aspect="auto")
        divider = make_axes_locatable(ax)
        cax = divider.append_axes("right", size="5%", pad=0.04)
        plt.colorbar(im, cax=cax, ax=ax, ticks=[0, 1])
    
        if len(points) > 0:
            ax.scatter([points[1]], [points[0]], s=150, color='#6cf086', marker='*')
        ax.set_xlabel(xlabel)
        ax.set_ylabel(ylabel)
        ax.set_xticks([0,1])
        ax.set_yticks([0,1])
        if add_corr:
            corr = np.corrcoef(x[:, 0], x[:, 1])[0, 1]
            ax.text(0.6, 0.88, r"$\rho=$"+f"{corr:.1f}", fontsize=25,
                    transform=ax.transAxes, color="white")
  7. michaeldeistler commented on Mar 19, 2024

    @michaeldeistler
    Contributor

    what exactly should joint_plot do?

  8. Ziaeemehr commented on Mar 19, 2024

    @Ziaeemehr
    Contributor

    it actually extract the joint plot implemented on pairplot, give an option to user to select arbitrary pair of parameters.
    I had issue for preparing image for publications to have arbitrary panels arrangements.

  9. michaeldeistler commented on Mar 19, 2024

    @michaeldeistler
    Contributor

    we have pairplot(..., subset=[0, 2, 3]), does this work?

  10. Ziaeemehr commented on Mar 19, 2024

    @Ziaeemehr
    Contributor

    I am not sure, think it still give a triangle plot right? including diagonal (marginal) and offdiagonal (joint plots). What if user only need one panel of this triangle plot (joint plot of parameter i, j).

  11. michaeldeistler commented on Mar 19, 2024

    @michaeldeistler
    Contributor

    ah, I see your point. I am not 100% convinced we need this, maybe we just leave this to users to implement themselves if really needed?

  12. Ziaeemehr commented on Mar 19, 2024

    @Ziaeemehr
    Contributor

    no worries, that's just a suggestion. 👍

  13. linked a pull request that will close this issue961 pairplot #1084on Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

beginner friendlydocshackathonkarma

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions