Created
May 28, 2019 16:14
-
-
Save dennissergeev/aeb5c9cb427e3c060396fb3692a37a41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def label_global_map(fig, ax, xticks, yticks, xoff=-10, yoff=-10, degree=False, **text_kw): | |
| """Label gridlines of a global cartopy map.""" | |
| geodetic_trans = ccrs.Geodetic() | |
| xlab_kw = ylab_kw = dict(va="center", ha="center", **text_kw) | |
| for xtick in xticks: | |
| s = format_lonlat(xtick, "lon", degree=degree) | |
| text_transform = offset_copy( | |
| geodetic_trans._as_mpl_transform(ax), fig=fig, units="points", x=0, y=yoff | |
| ) | |
| ax.text(xtick, -90, s, transform=text_transform, **xlab_kw) | |
| for ytick in yticks: | |
| s = format_lonlat(ytick, "lat", degree=degree) | |
| text_transform = offset_copy( | |
| geodetic_trans._as_mpl_transform(ax), fig=fig, units="points", x=xoff, y=0 | |
| ) | |
| ax.text(-180, ytick, s, transform=text_transform, **ylab_kw) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment