Skip to content

Allow colorbars to attach to inset axes#738

Merged
cvanelteren merged 7 commits into
mainfrom
feature/colorbar-inset-axes
Jun 23, 2026
Merged

Allow colorbars to attach to inset axes#738
cvanelteren merged 7 commits into
mainfrom
feature/colorbar-inset-axes

Conversation

@cvanelteren

Copy link
Copy Markdown
Collaborator

Closes #737
Colorbars requested on inset axes with side locations now stay attached to the inset instead of trying to allocate a subplot panel, which fails for axes without a subplot spec. The change remaps side requests to inset colorbar placements with side-appropriate default orientations and adds a regression test covering both direct inset-axis calls and figure-level calls that target an inset axis.

Colorbars requested on inset axes with side locations now stay attached to the inset instead of trying to allocate a subplot panel, which fails for axes without a subplot spec. The change remaps side requests to inset colorbar placements with side-appropriate default orientations and adds a regression test covering both direct inset-axis calls and figure-level calls that target an inset axis.
@cvanelteren

cvanelteren commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author
test

Example

import numpy as np
import ultraplot as uplt

data = np.random.rand(10, 10)
x = 0.35
fig, ax = uplt.subplots()
inax = ax.inset_axes([0.55, 0.45, x, x])
inax.pcolormesh(
    data,
    colorbar="t",
    colorbar_kw=dict(width=0.85),
)

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.18310% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/axes/base.py 94.33% 1 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@cvanelteren cvanelteren requested a review from gepcel June 20, 2026 00:26

@gepcel gepcel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't had time to test this yet—don't let me hold up the process.

@cvanelteren

Copy link
Copy Markdown
Collaborator Author

There is no rush @gepcel

@cvanelteren

Copy link
Copy Markdown
Collaborator Author

I will merge it by Friday if I don't here anything fyi @gepcel if you have time before to test stuff then would love to get your feedback.

Comment thread ultraplot/axes/base.py
def _get_side_colorbar_ticklocation(side, orientation, tickloc, ticklocation):
"""Return the outward-facing tick location for a side colorbar."""
if orientation == "horizontal":
default = "top" if side == "top" else "bottom"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If orientation is horizontal, I think the default should be "bottom".

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because both ultraplot and matplotlib use bottom as default position for horizontal colorbar. Other than this, I'm ok with this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good catch will do that.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can merge when you think it's ready. This is an execellent feature.

@cvanelteren cvanelteren merged commit b1320ed into main Jun 23, 2026
16 of 17 checks passed
@cvanelteren cvanelteren deleted the feature/colorbar-inset-axes branch June 23, 2026 11:03
@cvanelteren

Copy link
Copy Markdown
Collaborator Author

Thanks @gepcel

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.

[Feature request] inset colorbars

2 participants