proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics
https://proplot.readthedocs.io
MIT License
1.09k stars 100 forks source link

Shared lon/lat labels for rectangular map projections #79

Open mickaellalande opened 4 years ago

mickaellalande commented 4 years ago

I was trying to use shared labels, but I didn't succeed to make it work for longitude and latitude. At least if we write it as for other regular 2D data with x, y, as in the documentation example: https://proplot.readthedocs.io/en/latest/customizing.html#Shared-and-spanning-labels.

Here is an example (data: season_clim_diff.zip):

import xarray as xr
import proplot as plot

season_clim_diff = xr.open_dataarray('season_clim_diff.nc')

f, axs = plot.subplots(
    proj='cyl', proj_kw={'lon_0':180}, ncols=2, nrows=2, axwidth=3, share=3
)

seasons = ['DJF', 'MAM', 'JJA', 'SON']

for i, ax in enumerate(axs):
    m = ax.contourf(
        season_clim_diff.sel(season=seasons[i]), cmap='ColdHot', norm='midpoint'
    )
    ax.format(title=season_clim_diff.sel(season=seasons[i]).season.values)

f.colorbar(m, label="Snow Area Fraction [%]")
axs.format(
    geogridlinewidth=0.5, geogridcolor='gray8', geogridalpha=0.5, 
    labels=True, lonlines=60, latlines=30, 
    coast=True, ocean=True, oceancolor='gray4',
    suptitle="Annual snow cover bias (IPSL versus Rutgers)", 
    abc=True, abcstyle='a.'
)

proplot_subplots_share

Thus, with the share=3 option I would expect that the longitudes labels of the first line and the latitudes labels of the last column won't appear.

lukelbd commented 4 years ago

Shared labels are not currently supported for map projections but this is on my to-do list!

Just like Cartesian axes, I can implement share=3 as the default behavior for Plate Carrée, Mercator, and Miller rectangular projections. For other projections, since the edges are curved, share=0 should probably be the default, but no reason not to allow it.

One limitation of the "shared labels" feature is it currently only works for labels on the left and bottom. In the PR that addresses this issue, I'll also try to make them work for labels on the right and top. Will also see if I can implement sharing for groups of "twin" axes.