You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to do axis label sharing with geographic axis? #155
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 commentedon 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 commentedon Apr 13, 2025
Thanks for the suggestion! I took a look, and to support this properly, the
GeoAxisobject would need some extended functionality for shared axes. That would involve patching in methods similar to those used byCartesianAxes, 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 commentedon 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 commentedon Apr 14, 2025
@gepcel can you checkout #159
cvanelteren commentedon Apr 14, 2025
🥳
gepcel commentedon Apr 15, 2025
I'm not sure I did everything right. But I got an error.
cvanelteren commentedon Apr 15, 2025
Yes my bad I need to change the typo
cvanelteren commentedon 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 toocvanelteren commentedon Apr 15, 2025
There are still some bugs to figure with the automatic sharing. I will try to limit some.
cvanelteren commentedon Apr 15, 2025
Note to self: A few things need to happen.
test_geographic_multiple_projectionswill fail unless sharing is explicitly turned off which is not nice from a user experience.cvanelteren commentedon Apr 15, 2025
We could also just turn off sharing by default; which would be the easiest fix I guess.
gepcel commentedon 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 commentedon 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 commentedon Apr 18, 2025
This may be quite a niche requirement, so no worries, and feel free to skip this.
cvanelteren commentedon Apr 24, 2025
@gepcel think I can make it work.
cvanelteren commentedon Apr 25, 2025
@gepcel checkout the PR. Think it should be working properly now.
gepcel commentedon Apr 25, 2025
Works well as expected.
cvanelteren commentedon Apr 25, 2025
Cool! Will need a code review before merging. Keeping it open until merged.
gepcel commentedon Apr 25, 2025
Since this is open, this works for GeoAxes. Are this supposed to work for CartesianAxes when
xticklabelloc='both'oryticklabelloc='both'? I think GeoAxes is good enough.cvanelteren commentedon 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 commentedon Apr 25, 2025
Can you try:
cvanelteren commentedon 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 commentedon Apr 25, 2025
I got a fix for this but it is rather uggly...let's discuss in #176.
cvanelteren commentedon 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 commentedon May 11, 2025
Added in v.1.5, see https://github.com/Ultraplot/ultraplot/releases/tag/v1.5