Skip to content

Error adding rowlabels for custom gridspec #375

Closed

Description

@Holmgren825

Hey!
Will begin by thanking you for continuing the work with ultraplot!

I've encountered what I think is an error with the formatting of row labels using a custom gridspec. If the first column of a row is empty, the row does not seem to count. Here is a minimal example:

import ultraplot as plt
gridspec = [
    [1, 1, 2, 2],
    [0, 3, 3, 0],
    [4, 4, 5, 5],
]

fig, ax = plt.subplots(
    gridspec,
)
ax.format(rowlabels=["1", "2", "3"])

which raises an error: ValueError: Got 3 left labels but found 2 axes along the left side of the figure.

If I add a plot to the first column of the 2nd row, things works as expected.

gridspec = [
    [1, 1, 2, 2],
    [6, 3, 3, 0],
    [4, 4, 5, 5],
]

fig, ax = plt.subplots(
    gridspec,
)
ax.format(rowlabels=["1", "2", "3"])

produces

Image

Activity

  1. self-assigned this
    on Oct 21, 2025
  2. cvanelteren commented on Oct 21, 2025

    @cvanelteren
    Collaborator

    Thanks axs = self._get_align_axes(side) function is causing the issue (part of figure.py)

  3. cvanelteren commented on Oct 21, 2025

    @cvanelteren
    Collaborator

    The labeling does expect a grid, but do you want the label to appear immediate to the left or still on the outside grid? That is does the label for plot 3 need to be offset to the outside rectangle?

  4. Holmgren825 commented on Oct 21, 2025

    @Holmgren825
    ContributorAuthor

    I think that I would prefer the row labels to be vertically aligned (it is what I'm currently trying out manually placing a text annotation.)

    Edit: So basically like the working example above, but without the extra subplot.

  5. cvanelteren commented on Oct 21, 2025

    @cvanelteren
    Collaborator

    I can see how we can allow row labels but col labels in this example is not trivial.

  6. cvanelteren commented on Oct 21, 2025

    @cvanelteren
    Collaborator

    For example let's say we have

    [[1, 1, 2, 2], [0, 3 ,3 , 0], [4, 5, 6, 7]]
    

    where should the top labels be placed?

  7. Holmgren825 commented on Oct 21, 2025

    @Holmgren825
    ContributorAuthor

    Yes that is a good question. For me, row/collabels are useful when there is something shared among them, maybe they belong to a group. So for the latest example, maybe top labels doesn't make sense?

    To be consistent, perhaps being able to place labels according to the number of rows/cols reported by the axes object should work? For the example above I would've placed them at the bottom in that case. But I guess one can complicate things even further with something like [[1, 1, 2, 2], [0, 3 ,3 , 0], [4, 5, 6, 7]] where placing labels at the bottom wont work either.

  8. cvanelteren commented on Oct 21, 2025

    @cvanelteren
    Collaborator

    see #376

  9. cvanelteren commented on Oct 21, 2025

    @cvanelteren
    Collaborator

    We can allow for placing it on the left but error on the rest in the case I provided.

  10. cvanelteren commented on Oct 21, 2025

    @cvanelteren
    Collaborator

    e.g. this works:

    [[1, 1, 2, 2], [0, 3 ,3 , 0], [4, 5, 6, 7]]
    

    for left but no top (when n = 3) or bottom labels (n = 3 unless n = 5)

  11. cvanelteren commented on Oct 22, 2025

    @cvanelteren
    Collaborator

    I think it makes most sense if we "view" the labels as putting them on the axis that you hit first as if you were looking from the side of the grid, i.e.:

    Image
  12. cvanelteren commented on Oct 22, 2025

    @cvanelteren
    Collaborator

    So in this case:

    Image

    You have 4 viewing from the right but 3 viewing from the left.

  13. cvanelteren commented on Oct 23, 2025

    @cvanelteren
    Collaborator

    Fixed on main!

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions