You're right—this isn't currently supported and would mainly make sense for rectilinear projects. That said, it’s definitely a feature we could consider adding. You can check out the relevant commit here: 2085c2f1. If you're interested, feel free to open a PR to kick things off!
Thanks for the suggestion! I took a look, and to support this properly, the GeoAxis object would need some extended functionality for shared axes. That would involve patching in methods similar to those used by CartesianAxes, while also ensuring all projections involved are rectilinear (and the same). The patching would be possible relatively easily but requires proper testing and disproportionate use for a feature of which I think is rather niche (but do correct me when I am wrong).
Since this is a fairly niche use case, a quick workaround for now would be to manually disable the labels. I agree it's a worthwhile improvement, and I might revisit this when I have a bit more time to work on it -- otherwise I am willing to review pull requests in the mean time.
@gepcel fixed the typos. Should be good now I think. hold on, both sides are not behaving correctly, the others are fine. Edit 2: Actually try it, not sure if this is what you wanted or you want the inner labels to turn off too
Axes are automatically shared in UltraPlot. The checks needs to be expanded such that it turns off the sharing when the sharing won't be possible. In principle mixing cartopy and basemap should work fine for rectilinear projections but there are some quirks that still exist in this context
Constructively building a figure such as in test_geographic_multiple_projections will fail unless sharing is explicitly turned off which is not nice from a user experience.
I see. I have some local changes that make this possible. It is a bit tricky as UltraPlot turns on axis sharing by the default which causes issues with projection classes. I am making some internal changes to see if this is possible.
Since this is open, this works for GeoAxes. Are this supposed to work for CartesianAxes when xticklabelloc='both' or yticklabelloc='both'? I think GeoAxes is good enough.
To explain what is happening. The axes are shared which makes the left most and bottom most subplot the references. If you set the ticks to be top and right, it updates them for the references. What you want, I think, is set the top labels on for the top and right labels for the right most axes.
@gepcel can you checkout the PR again. This ended up a lot more work than I thought and I am a bit hesitant to merge this without proper testing. Internally I had to add features that are frowned upon by matplotlib. I added the ability to toggle axis sharing on and off. There we also numerous bugs with the sharing caused by the difference in backends that deviate from the default matplotlib standards. For example, cartopy does not actually create tick labels but merely puts text in the correct places, whereas basemap handles this completely differently.
Activity
cvanelteren commented on Apr 12, 2025
You're right—this isn't currently supported and would mainly make sense for rectilinear projects. That said, it’s definitely a feature we could consider adding. You can check out the relevant commit here: 2085c2f1. If you're interested, feel free to open a PR to kick things off!
cvanelteren commented on Apr 13, 2025
Thanks for the suggestion! I took a look, and to support this properly, the GeoAxis object would need some extended functionality for shared axes. That would involve patching in methods similar to those used by CartesianAxes, while also ensuring all projections involved are rectilinear (and the same). The patching would be possible relatively easily but requires proper testing and disproportionate use for a feature of which I think is rather niche (but do correct me when I am wrong).
Since this is a fairly niche use case, a quick workaround for now would be to manually disable the labels. I agree it's a worthwhile improvement, and I might revisit this when I have a bit more time to work on it -- otherwise I am willing to review pull requests in the mean time.
cvanelteren commented on Apr 14, 2025
Update:
Think I figured something out:
Still in a pretty rough state but it is getting somewhere. More to follow soon 👀
cvanelteren commented on Apr 14, 2025
@gepcel can you checkout #159
cvanelteren commented on Apr 14, 2025
🥳
gepcel commented on Apr 15, 2025
I'm not sure I did everything right. But I got an error.
In [1]: import ultraplot as pplt In [2]: fig, axs = pplt.subplots(ncols=2, nrows=2, projection='cyl', refwidth='5cm', share='all') In [3]: axs.format(lonlim=(0, 60), latlim=(-20, 20), ...: lonlines=15, latlines=10, lonlabels='both', latlabels='both') --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[3], line 1 ----> 1 axs.format(lonlim=(0, 60), latlim=(-20, 20), 2 lonlines=15, latlines=10, lonlabels='both', latlabels='both') File ~\Downloads\ultraplot-feat-shared-geo-new\ultraplot\gridspec.py:1630, in SubplotGrid.format(self, **kwargs) 1600 @docstring._snippet_manager 1601 def format(self, **kwargs): 1602 """ 1603 Call the ``format`` command for the `~SubplotGrid.figure` 1604 and every axes in the grid. (...) 1628 ultraplot.config.Configurator.context 1629 """ -> 1630 self.figure.format(axs=self, **kwargs) File ~\Downloads\ultraplot-feat-shared-geo-new\ultraplot\internals\warnings.py:118, in _rename_kwargs.<locals>._decorator.<locals>._deprecate_kwargs_wrapper(*args, **kwargs) 113 key_new = key_new.format(value) 114 _warn_ultraplot( 115 f"Keyword {key_old!r} was deprecated in version {version} and may " 116 f"be removed in {next_release()}. Please use {key_new!r} instead." 117 ) --> 118 return func_orig(*args, **kwargs) File ~\Downloads\ultraplot-feat-shared-geo-new\ultraplot\figure.py:1694, in Figure.format(self, axs, figtitle, suptitle, suptitle_kw, llabels, leftlabels, leftlabels_kw, rlabels, rightlabels, rightlabels_kw, blabels, bottomlabels, bottomlabels_kw, tlabels, toplabels, toplabels_kw, rowlabels, collabels, includepanels, **kwargs) 1687 for ax in axs: 1688 kw = { 1689 key: value 1690 for cls, kw in kws.items() 1691 for key, value in kw.items() 1692 if isinstance(ax, cls) and not classes.add(cls) 1693 } -> 1694 ax.format(rc_kw=rc_kw, rc_mode=rc_mode, skip_figure=True, **kw, **kwargs) 1696 # Warn unused keyword argument(s) 1697 kw = { 1698 key: value 1699 for name in kws.keys() - classes 1700 for key, value in kws[name].items() 1701 } File ~\Downloads\ultraplot-feat-shared-geo-new\ultraplot\axes\geo.py:884, in GeoAxes.format(self, extent, round, lonlim, latlim, boundinglat, longrid, latgrid, longridminor, latgridminor, ticklen, lonticklen, latticklen, latmax, nsteps, lonlocator, lonlines, latlocator, latlines, lonminorlocator, lonminorlines, latminorlocator, latminorlines, lonlocator_kw, lonlines_kw, latlocator_kw, latlines_kw, lonminorlocator_kw, lonminorlines_kw, latminorlocator_kw, latminorlines_kw, lonformatter, latformatter, lonformatter_kw, latformatter_kw, labels, latlabels, lonlabels, rotatelabels, loninline, latinline, inlinelabels, dms, labelpad, labelcolor, labelsize, labelweight, **kwargs) 882 latlabels = _not_none(latlabels, labels) 883 # Set the ticks --> 884 self._toggle_ticks(lonlabels, "x") 885 self._toggle_ticks(latlabels, "y") 886 lonarray = self._to_label_array(lonlabels, lon=True) File ~\Downloads\ultraplot-feat-shared-geo-new\ultraplot\axes\geo.py:596, in GeoAxes._toggle_ticks(self, label, which) 594 case "all" | "both": 595 if which == "x": --> 596 self.xaxis.set_position("both") 597 else: 598 self.yaxis.set_position("both") AttributeError: 'XAxis' object has no attribute 'set_position'cvanelteren commented on Apr 15, 2025
Yes my bad I need to change the typo
cvanelteren commented on Apr 15, 2025
@gepcel fixed the typos. Should be good now I think. hold on, both sides are not behaving correctly, the others are fine. Edit 2: Actually try it, not sure if this is what you wanted or you want the inner labels to turn off too
cvanelteren commented on Apr 15, 2025
There are still some bugs to figure with the automatic sharing. I will try to limit some.
cvanelteren commented on Apr 15, 2025
Note to self: A few things need to happen.
cvanelteren commented on Apr 15, 2025
We could also just turn off sharing by default; which would be the easiest fix I guess.
gepcel commented on Apr 15, 2025
What should axis sharing do when it's on both sides? For example with a single axes, yticklabel is shown on both left and right sides.
And with subplots, the first axis gets yticklabel on both left and right sides, but the second gets no yticklabels.
And this holds for geoaxes, too. With subplots, both subplots get latlabels on both left and right sides.
I may be wrong, but I'm expecting something like:
cvanelteren commented on Apr 16, 2025
I see. I have some local changes that make this possible. It is a bit tricky as UltraPlot turns on axis sharing by the default which causes issues with projection classes. I am making some internal changes to see if this is possible.
9 remaining items
gepcel commented on Apr 18, 2025
This may be quite a niche requirement, so no worries, and feel free to skip this.
cvanelteren commented on Apr 24, 2025
@gepcel think I can make it work.
cvanelteren commented on Apr 25, 2025
@gepcel checkout the PR. Think it should be working properly now.
gepcel commented on Apr 25, 2025
Works well as expected.
cvanelteren commented on Apr 25, 2025
Cool! Will need a code review before merging. Keeping it open until merged.
gepcel commented on Apr 25, 2025
Since this is open, this works for GeoAxes. Are this supposed to work for CartesianAxes when xticklabelloc='both' or yticklabelloc='both'? I think GeoAxes is good enough.
cvanelteren commented on Apr 25, 2025
Could you please clarify? The PR targets mostly GeoAxes sharing and the behavior for Cartesian plots is supposed to be unchanged. An example may help.
gepcel commented on Apr 25, 2025
Can you try:
cvanelteren commented on Apr 25, 2025
Ah I see... that is a different bug.
To explain what is happening. The axes are shared which makes the left most and bottom most subplot the references. If you set the ticks to be top and right, it updates them for the references. What you want, I think, is set the top labels on for the top and right labels for the right most axes.
cvanelteren commented on Apr 25, 2025
I got a fix for this but it is rather uggly...let's discuss in #176.
cvanelteren commented on May 8, 2025
@gepcel can you checkout the PR again. This ended up a lot more work than I thought and I am a bit hesitant to merge this without proper testing. Internally I had to add features that are frowned upon by matplotlib. I added the ability to toggle axis sharing on and off. There we also numerous bugs with the sharing caused by the difference in backends that deviate from the default matplotlib standards. For example, cartopy does not actually create tick labels but merely puts text in the correct places, whereas basemap handles this completely differently.
cvanelteren commented on May 11, 2025
Added in v.1.5, see https://github.com/Ultraplot/ultraplot/releases/tag/v1.5