Samreay / ChainConsumer

Corner plots, LaTeX tables and plotting walks.
https://samreay.github.io/ChainConsumer
MIT License
79 stars 17 forks source link

Chain labels/legends when using `plot_contour`. #113

Closed arthurmloureiro closed 8 months ago

arthurmloureiro commented 8 months ago

Hi!

I am trying to use "plot_contours" (in a case where I don't need a triangle style plot) for making different panels of parameter combinations.

However, when using 2 chains, I don't seem to be able to make the labels or the chain names to appear.

Is there a way of doing this?

Here's an example code:

fig, axes = plt.subplots(ncols=3, nrows=3, figsize=(10, 10))
c=0
for i in range(3):
    for j in range(3):
        plot_contour(axes[i,j], test_c, px=cols_chain[c], py=cols_chain[c+1])
        plot_contour(axes[i,j], test_c_2, px=cols_chain[c], py=cols_chain[c+1])
        axes[i,j].set_ylabel(cols_chain[c+1])
        axes[i,j].set_xlabel(cols_chain[c])
        c+=1
plt.legend(loc=0)
plt.tight_layout()

Including the label='Name 1' in the plot_contour seems to break so the legend has no artists with labels to create the legend.

Samreay commented 8 months ago

Ah yeah, legends are fun. I had my own bevy of issues getting them working as I wanted, and so this is actually done manually in the generic plot function.

Specifically, you may be interested in get_artists_from_chains, wherein the code used is effectively:

artists = get_artists_from_chains(base.chains)
leg = ax.legend(handles=artists, **legend_kwargs)

If you dont have the data put into the Chains objects though, this may not be as simple a process as youd like though. But give that function a look over, let me know if it helps / you can use it, or if its not useful :)

arthurmloureiro commented 8 months ago

Thanks!

(Apologies, I will have to open another issue about something else...)