Skip to content

Conversation

@gbrammer
Copy link
Contributor

@gbrammer gbrammer commented Dec 4, 2025

This PR adds a function to return the axis from fig.axes corresponding to a particular pair of plotted data.

For example

import numpy as np
import corner

np.random.seed(1)
data = np.random.normal(size=(1000, 3))

labels = ["a", "b", "c"]
fig = corner.corner(data, labels=labels)

# The axis with x=a, y=b
ix = labels.index("a")
iy = labels.index("b")
ax = corner.axis_from_param_indices(fig, ix, iy)

ax.text(
    0.5, 0.5,
    f"x={labels[ix]}   y={labels[iy]}",
    fontsize=14,
    ha="center", va="center",
    color="r", transform=ax.transAxes, bbox={"fc": "w"}
)

# Test the inverse: ix = iy = 0 is the histogram axis for "a"
ix = iy = 0
i = corner.axis_from_param_indices(fig, ix, iy, return_axis=False)
ix_i, iy_i = corner.param_indices_from_axis(fig, i)
ax = fig.axes[i]

ax.text(
    0.5, 0.5,
    f"x={labels[ix_i]}  (histogram)",
    fontsize=14,
    ha="center", va="center",
    color="r", transform=ax.transAxes, bbox={"fc": "w"}
)
corner

@dfm
Copy link
Owner

dfm commented Jan 3, 2026

Thank you!

@dfm dfm merged commit 558ce0c into dfm:main Jan 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants