Skip to content

Conversation

@cvanelteren
Copy link
Collaborator

@cvanelteren cvanelteren commented Oct 29, 2025

Closes #393
Closes #392

Enables fig.colorbar() to use both ax (positioning) and span/rows/cols (extent) parameters together. Previously, span was ignored when ax was provided.

Examples

# Bottom colorbar spanning only columns 1-2
fig, axs = uplt.subplots(nrows=2, ncols=3)
fig.colorbar(cm, ax=axs[0, :], span=(1, 2), loc="bottom")

# Right colorbar spanning only rows 1-2
fig, axs = uplt.subplots(nrows=3, ncols=2)
fig.colorbar(cm, ax=axs[:, 0], rows=(1, 2), loc="right")

Notes

  • Use span= or cols= for horizontal colorbars (top/bottom)
  • Use rows= for vertical colorbars (left/right)
  • Validation errors/warnings guide correct parameter usage
  • Array behavior preserved: fig.colorbar(cm, ax=axs[:]) still works
  • Added 15 tests to test_colorbar.py
  • Fully backward compatible

@cvanelteren cvanelteren requested a review from Copilot October 29, 2025 20:30

This comment was marked as resolved.

@cvanelteren cvanelteren changed the title Allow multi-span colorbars Feature: Allow multi-span colorbars Oct 29, 2025
@codecov

This comment was marked as resolved.

@cvanelteren cvanelteren requested a review from beckermr October 30, 2025 07:52
Copy link
Collaborator

@beckermr beckermr left a comment

Choose a reason for hiding this comment

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

I don't get why span/rows/cols start with the first column at 1 instead of at 0. Has it always been this way?

It makes this code confusing:

fig.colorbar(cm, ax=axs[0, 0], span=(1, 2), loc="bottom")

The axes indices are offset by 1 from the span values.

Copy link
Collaborator

@beckermr beckermr left a comment

Choose a reason for hiding this comment

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

NVM it has been that way always. Very confusing but it is what it is.

@beckermr beckermr merged commit 946c33a into Ultraplot:main Oct 31, 2025
25 checks passed
@cvanelteren
Copy link
Collaborator Author

NVM it has been that way always. Very confusing but it is what it is.

I read it as it takes x rows or y columns together with ax it will then define a rectangle around it.

@cvanelteren cvanelteren deleted the fix-figure-cbars branch October 31, 2025 12:38
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.

Figure.colorbar does not respect loc when passed Add colorbar that span multiple columns at a specified row in GridSpec

2 participants