Open oliviermarti opened 1 month ago
I think this is because the gridliner does not use/respect the xaxis.get_major_formatter()
. It is more general and also has "geo" labels that aren't on the x/y axis. So, you're forced to pass in the formatter to the gridliner directly.
I'm not sure how hard it would be to make the gridliner be aware of the x/y axis properties, but it seems like it would be a nice update.
The formatters are just attributes on the gridliner so if you want to change them after you created it you can just do
gl = ax.gridlines(draw_labels=True, crs=ProjIn)
gl.xformatter = cartopy.mpl.ticker.LongitudeFormatter(dms=False, number_format='03.1f')
gl.yformatter = cartopy.mpl.ticker.LatitudeFormatter(number_format='03.1f')
I'm not convinced that GridLiner
should respect the settings in .xaxis
and .yaxis
: users can use them instead of gridliner if they prefer (see example). There is also nothing to stop you using the x/y-axis labels and a gridliner (or multiple gridliners) and you might want different formats for each of them. I admit I do not have use-cases in mind for those but to me it makes sense to maintain separation of concerns.
Description
Cartopy does not format longitude/latitude axis
Code to reproduce
The problem
The last two lines are not effective, and cartopy still displays latitudes as '7.5°S 7°S ...', when it should be '7.5°S 7.0°S ...'
Work around
The result is correct if one uses :
Operating system and others
Version python : 3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:13:44) [Clang 16.0.6 ] Version numpy : 1.26.4 Version xarray : 2024.6.0 Version Matplotlib : 3.9.1 Version Cartopy : 0.23.0