Skip to content

Fix ngrids support in axes_grid.Grid(). #27972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2025
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Mar 24, 2024

This also restores axes_row and axes_column to their behavior prior to 88e0d84 (which is the commit that broke ngrids support).

Closes a small part of #27963.

PR summary

PR checklist

@timhoffm
Copy link
Member

timhoffm commented Mar 24, 2024

Since no user has reported that this is broken for more than 3 years, I’m considering removing that parameter. The naming is confusing and the bug can be regarded a very hard deprecation 😏 . If we want such functionality, we could either re-introduce it under a better name such as naxes, or consider whether there is a better and more flexible API altogether: For example n_rows_cols could take a 2D bool array, specifying at which positions one wants Axes.

@anntzer
Copy link
Contributor Author

anntzer commented Mar 24, 2024

I don't really mind either way. However, if you're going to refactor this, I wonder if it would be better to instead have a arrange_grid() that takes the output of Figure.subplots() or Figure.subplot_mosaic() (i.e. an array or a dict of axes) and sets the locators on them as needed and optionally adds colorbars. This would allow a more orthogonal API (think "composition over inheritance", even though there isn't inheritance here) -- in particular, you wouldn't need provide rect, ngrids, share_all/share_x/share_y (you'd just read these off the axes that are passed to you.

I guess the required signature would be

def arrange_grid(
    axes,  # array or dict
    axes_pad=0.02,
    aspect=???,
    label_mode="L",  # not even clear this is needed; label_outer() could be enough
    cbar_mode="each"/"single"/"edge"/"none",  # "none" case covers the plain Grid()
    # followed with the cbar_foo kwargs
): ...

@jklymak
Copy link
Member

jklymak commented Mar 24, 2024

How is that different than layout='compressed'?

@anntzer
Copy link
Contributor Author

anntzer commented Mar 24, 2024

I actually agree with the comment in #27963 that we should just get rid of axes_grid and promote layout="compressed" as much as possible. (I guess the "different-sized images" case could perhaps be handled nowadays via box_aspect? Does CL know anything about that?)

@jklymak
Copy link
Member

jklymak commented Mar 24, 2024

CL knows about width- and height ratios. However it doesn't know about the aspect ratio of the axes inside, and is best suited to axes that don't have aspect constraints. (You can write the problem including aspect constraints but the optimization goes from 2n to n^2 and becomes very slow.)

I'd not be against adding a new method to the top level library that does a grid of fixed aspect axes like this. But we should carefully decide how it is different than what we already have and if it's worth it, versus letting the folks who need this do a bit of fussing with width and height ratios.

@anntzer
Copy link
Contributor Author

anntzer commented Mar 24, 2024

(I don't have strong feelings about axes_grid; this PR was mostly motivated by fixing a regression I caused some time ago...)

@timhoffm timhoffm added the status: needs comment/discussion needs consensus on next step label Apr 2, 2024
@timhoffm
Copy link
Member

timhoffm commented Apr 2, 2024

I still want to decide whether we use the fact that this parameter was not working for a long time to remove or rename it.

Since this was found internally and not by users, we have no indication that somebody is using it, so no need to hurry and fix it.

@timhoffm timhoffm added this to the v3.10.0 milestone Apr 2, 2024
@timhoffm timhoffm self-assigned this Apr 2, 2024
@ksunden ksunden modified the milestones: v3.10.0, v3.11.0 Oct 11, 2024
@ebarcelosf
Copy link

hi, can i solve this issue?

@timhoffm
Copy link
Member

timhoffm commented Oct 17, 2024

This is a solution proposal that needs decision from core developers. You cannot help here.

@anntzer
Copy link
Contributor Author

anntzer commented Feb 21, 2025

@timhoffm Can we reach a decision on this? I still mildly prefer restoring support for ngrids (perhaps prior to larger changes later) but don't really mind if we decide instead to just drop it. But the current situation (a non-working but documented kwarg) just seems the worst.

@timhoffm
Copy link
Member

timhoffm commented Feb 21, 2025

I'm still for deprecate and note that this has not been working anyway. Nobody has complained about this the last 4 years. If you think the feature is helpful let's reintroduce it right away under a new meaningful name such as n_axes.

Edit: Or fix and @rename_parameter which is effectively the same. - I just don't want that people are using the unintuitive name ngrids.

@anntzer
Copy link
Contributor Author

anntzer commented Feb 22, 2025

OK, renamed.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Please fix the Attributes doc. Read-only property is optional.

@QuLogic
Copy link
Member

QuLogic commented Feb 24, 2025

Syntax seems broken somewhere.

@anntzer
Copy link
Contributor Author

anntzer commented Feb 24, 2025

oopsie. refixed.

Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

LGTM - I think worth noting ImageGrid has changed too. Feel free to self merge if the API note is updated

This attribute has been deprecated and renamed ``n_axes``, consistently with
the new name of the `~.axes_grid.Grid` constructor parameter that allows
setting the actual number of axes in the grid (the old parameter, ``ngrids``,
did not actually work since Matplotlib 3.3).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
did not actually work since Matplotlib 3.3).
did not actually work since Matplotlib 3.3).
The same change has been made in ``axes_grid.ImageGrid``.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

This also restores axes_row and axes_column to their behavior prior to 88e0d84
(which is the commit that broke ngrids support).
@timhoffm timhoffm merged commit b32de5c into matplotlib:main Mar 26, 2025
37 of 41 checks passed
@anntzer anntzer deleted the gn branch March 26, 2025 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants