In #23550, we began explicitly checking for the documented values of label_mode, ('All', 'L', '1'), which this runs afoul of. It appears the previous code let '' (or any option not handled) essentially work as a noop for set_label_mode().
Based on the output when the example worked, '1' would be fine behavior-wise, but that currently produces in this example:
/Users/rmay/repos/cartopy/examples/miscellanea/axes_grid_basic.py:48: MatplotlibDeprecationWarning: The resize_event function was deprecated in Matplotlib 3.6 and will be removed two minor releases later. Use callbacks.process('resize_event', ResizeEvent(...)) instead.
fig = plt.figure()
Traceback (most recent call last):
File "/Users/rmay/repos/cartopy/examples/miscellanea/axes_grid_basic.py", line 78, in <module>
main()
File "/Users/rmay/repos/cartopy/examples/miscellanea/axes_grid_basic.py", line 49, in main
axgr = AxesGrid(fig, 111,
File "/Users/rmay/miniconda3/envs/py310/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line 391, in __init__super().__init__(
File "/Users/rmay/miniconda3/envs/py310/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line 174, in __init__self.set_label_mode(label_mode)
File "/Users/rmay/miniconda3/envs/py310/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line 295, in set_label_mode
_tick_only(ax, bottom_on=True, left_on=True)
File "/Users/rmay/miniconda3/envs/py310/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line 16, in _tick_only
ax.axis["bottom"].toggle(ticklabels=bottom_off, label=bottom_off)
TypeError: 'method' object is not subscriptable
This is because, while AxesGrid supposedly supports arbitrary classes by passing axes_class, there's a huge caveat: the default is mpl_toolkits.axes_grid1.mpl_axes.Axes (TERRIBLY CONFUSING NAME--it's imported as just Axes in axis_grid.py). This is a custom subclass that adds:
Fix AxesGrid to work more generally with axes_class--monkey-patch/subclass to add the necessary modifications
Document that axes_class needs to have certain behavior
Fix AxesGrid to not rely on a property that OVERRIDES matplotlib.axes.Axes.axis with a different type that also manually dispatches to the unbound axis() method 😱
Just wanted to clarify that the previous (accidentally) "working" behavior (at least for Cartopy) wasn't no labels:
Ahh, sorry about that. Was reading on the phone in bed and wanted to confirm that I broke something...
Looking at the code, it is not really obvious what happens with the "all" case, which somehow is documented to do what is the expected output(?), and the difference to not doing anything.
I'll try to look more into it over the weekend. I guess either passing "all" may work and one should deprecate passing something else or we should add a fourth option corresponding to passing something else (and deprecate passing anything other than any of the four options). Not sure if we should revert for 3.6 or if it is OK to deprecate as part of 3.6.1.
Just to confirm @dopplershift : will you get the same/correct behavior if you pass "all"? I cannot see any difference in my tests...
If so, I think a deprecation warning of passing an undefined label_mode is the (first) way to go.
If not, we should come up with a good name for that label_mode.
(It may be that toggle which is called later is not properly working though, #23595. But 'all' will turn on the labels, which seems to be the wanted thing here.)
I tried to run the Cartopy example from the git version and failed, so I cannot confirm that it is working. Just in case, I added a fourth option, "keep" for this case.
@oscargus No, it doesn't work with 'all' for the same reasons as I originally enumerated above: AxesGrid, while it advertises support for using a custom class, only works with classes that do that terrible process of overriding the .axis attribute with a custom dictionary. IMO, while restoring the previous option is a nice work-around, AxesGrid needs a refactor to do less silly things--but I'm waiting to hear everyone else weigh in.
If layout='compress' really is an AxesGrid replacement, I'm happy to update the Cartopy example to use it eventually. Seeing as it was only added in 3.6, though, having 3.6.1 unbreak the example (#24084) will be good.
That certainly eliminates any interest I have in refactoring AxesGrid.
Off topic: I think layout='compress' is a good replacement for AxesGrid, however it is new, and has the frailty of a layout engine that solves a set of constrains. Conversely, AxesGrid is completely deterministic, and hence less fragile. So I could easily be convinced that an AxesGrid artist would be a good feature for the main library with the right API and design choices.
@tacaswell Yeah, saw that. Looks good. Trying to figure out the right balance in moving a fringe example to a new feature that just got released 2 weeks ago.
If it helps, I also tried the example with layout='constrained' and the default figsize. That also looked good, because it just happens that those maps are the right shape to fit 6 of them well.
But even if the Cartopy example changes to a newer approach, it’s still good to unbreak 3.6.1 for any Cartopy users who adapted the example into their code.
Activity
oscargus commented on Sep 29, 2022
A quick thought (since I broke it): there should be a way to not get any labels. Maybe 'none'?
(If I recall correctly all those three do generate labels.)
Then, maybe we also want to do something more..
dopplershift commented on Sep 29, 2022
Just wanted to clarify that the previous (accidentally) "working" behavior (at least for Cartopy) wasn't no labels:
EDIT: I think it was more "don't touch my labels".
jklymak commented on Sep 29, 2022
Super off topic, but does this example work with a normal grid of subplots with layout='compress'?
oscargus commented on Sep 30, 2022
Ahh, sorry about that. Was reading on the phone in bed and wanted to confirm that I broke something...
Looking at the code, it is not really obvious what happens with the "all" case, which somehow is documented to do what is the expected output(?), and the difference to not doing anything.
I'll try to look more into it over the weekend. I guess either passing "all" may work and one should deprecate passing something else or we should add a fourth option corresponding to passing something else (and deprecate passing anything other than any of the four options). Not sure if we should revert for 3.6 or if it is OK to deprecate as part of 3.6.1.
rcomer commented on Oct 1, 2022
oscargus commented on Oct 2, 2022
Just to confirm @dopplershift : will you get the same/correct behavior if you pass "all"? I cannot see any difference in my tests...
If so, I think a deprecation warning of passing an undefined label_mode is the (first) way to go.
If not, we should come up with a good name for that label_mode.
(It may be that toggle which is called later is not properly working though, #23595. But 'all' will turn on the labels, which seems to be the wanted thing here.)
oscargus commented on Oct 2, 2022
I tried to run the Cartopy example from the git version and failed, so I cannot confirm that it is working. Just in case, I added a fourth option, "keep" for this case.
dopplershift commented on Oct 2, 2022
@oscargus No, it doesn't work with 'all' for the same reasons as I originally enumerated above: AxesGrid, while it advertises support for using a custom class, only works with classes that do that terrible process of overriding the .axis attribute with a custom dictionary. IMO, while restoring the previous option is a nice work-around, AxesGrid needs a refactor to do less silly things--but I'm waiting to hear everyone else weigh in.
jklymak commented on Oct 2, 2022
Layout='compress' is an AxesGrid replacement
If someone refactors AxesGrid I'd suggest they do so on the main library and allow a clean API break with the toolkit version.
dopplershift commented on Oct 3, 2022
If layout='compress' really is an AxesGrid replacement, I'm happy to update the Cartopy example to use it eventually. Seeing as it was only added in 3.6, though, having 3.6.1 unbreak the example (#24084) will be good.
That certainly eliminates any interest I have in refactoring AxesGrid.
tacaswell commented on Oct 3, 2022
@dopplershift See @rcomer 's comment above.
jklymak commented on Oct 3, 2022
On topic: agree with unbreaking 3.6.1.
Off topic: I think layout='compress' is a good replacement for AxesGrid, however it is new, and has the frailty of a layout engine that solves a set of constrains. Conversely, AxesGrid is completely deterministic, and hence less fragile. So I could easily be convinced that an AxesGrid artist would be a good feature for the main library with the right API and design choices.
dopplershift commented on Oct 3, 2022
@tacaswell Yeah, saw that. Looks good. Trying to figure out the right balance in moving a fringe example to a new feature that just got released 2 weeks ago.
rcomer commented on Oct 3, 2022
If it helps, I also tried the example with layout='constrained' and the default figsize. That also looked good, because it just happens that those maps are the right shape to fit 6 of them well.
But even if the Cartopy example changes to a newer approach, it’s still good to unbreak 3.6.1 for any Cartopy users who adapted the example into their code.
QuLogic commented on Oct 6, 2022
IIUC, this is fixed by #24084