Skip to content

Add colorbar that span multiple columns at a specified row in GridSpec #392

Closed

Description

@Holmgren825

Hey!

Not sure if this is my own lack of understanding or currently not possible. But I'm wondering if it is possible to add a colobar that spans multiple columns at a specific row in a grid? Using matplotlib we can do something like this

fig, axs = plt.subplots(nrows=2, ncols=2)
rng = np.random.default_rng()
data = rng.random((100, 100))
cm = axs[0, 0].pcolormesh(data)
fig.colorbar(cm, ax=axs[0, :], location="bottom")

and get

Image

while trying something similar in ultraplot

fig, axs = uplt.subplots(nrows=2, ncols=2)
rng = np.random.default_rng()
data = rng.random((100, 100))
cm = axs[0, 0].pcolormesh(data)
fig.colorbar(cm, ax=axs[0, :], location="bottom")

gives

Image

I think this would be helpful when sharing colormaps among columns, but not rows.

Activity

  1. cvanelteren commented on Oct 29, 2025

    @cvanelteren
    Collaborator

    You are correct. I don't think we support that at this moment for inside axes colorbars. On the outside is possible, e.g.

    import ultraplot as uplt, numpy as np, pandas as pd
    
    fig, axs = uplt.subplots(nrows=2, ncols=2)
    rng = np.random.default_rng()
    data = rng.random((100, 100))
    cm = axs[0, 0].pcolormesh(data)
    fig.colorbar(cm, span=(1, 2), loc="top")
    uplt.show(block=1)
  2. cvanelteren commented on Oct 29, 2025

    @cvanelteren
    Collaborator

    Note span is not necessary as it defaults to the entire range

  3. cvanelteren commented on Oct 29, 2025

    @cvanelteren
    Collaborator

    But I do see a bug that loc is not being listened to when using fig.colorbar

  4. cvanelteren commented on Oct 29, 2025

    @cvanelteren
    Collaborator

    Found a fix for #393 but need to tool a bit for the other one, keep you posted @Holmgren825

  5. Holmgren825 commented on Oct 30, 2025

    @Holmgren825
    ContributorAuthor

    Nice, quick work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions