handley-lab/fgivenx

Histogram background instead of contourf?

Stefan-Heimersheim opened this issue · 1 comments

Is your feature request related to a problem? Please describe.
I thought replacing the filled contours by a histogram might be a nice idea. In particular to distinguish flat contours or generally debug why contours look weird. Here's an example how it could look like, compared to contourf:
fr2
fr1

However for a histogram, maybe a different normalization (e.g. sum over column or row of 2d hist = 1) might be more appropriate.

I stopped working on this for now (I went back to using contours), but in case anyone is looking for something like this let me know and I can work out a PR. Also, here is the simple code I used in plot() to make the above plots happen:

    area = kwargs.pop('area', 'contourf')

    [...]

    if area=='pcolormesh':
        cbar = ax.pcolormesh(x, y, z, cmap=colors, alpha=alpha, **kwargs)

    [...]
    
    # Plot the filled contours onto the axis ax
    if area=='contourf':
        print("x", x)
        print("y", y)
        print("z", z)
        cbar = ax.contourf(x, y, z, cmap=colors, levels=contour_color_levels, alpha=alpha)
        # Rasterize contours (the rest of the figure stays in vector format)
        if rasterize_contours:
            for c in cbar.collections:
                c.set_rasterized(True)
        # Remove those annoying white lines
        for c in cbar.collections:
            c.set_edgecolor("face")

    if area=="none":
        cbar = None

Edit: I just noticed that one of course would want a histogram of the non-smoothed samples, but the values given to plot() are already smoothed by scipy.stats.gaussian_kde(samples) in PMF()

If you're willing to put this into a PR, I would be happy to iterate over the code to get it up and running as expected. One of the things I would like to do at some point is to make a tighter integration of this package with anesthetic e.g. for including weighted samples and pandas like dataframes.