proplot-dev / proplot

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

How can I rotate lat ticklabels of GeoAxes? #415

Closed gepcel closed 1 year ago

gepcel commented 1 year ago

In the following example, I want to rotate the lat ticklabels by 90°, How can I do that?

import proplot as pplt
fig, ax = pplt.subplots(proj='cyl')
ax.format(lonlim=[10.1, 10.13],latlim=[30.1,30.13], lonlines=0.01, latlines=0.015,labels=True)

image

Steps to do in matplotlib:

from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
ax = plt.subplot(projection=ccrs.PlateCarree())
ax.set_extent([10.1,10.13,30.1,30.13])
ax.set_xticks([10.11,10.12])
ax.set_yticks([30.11,30.12])
ax.xaxis.set_major_formatter(LongitudeFormatter())
ax.yaxis.set_major_formatter(LatitudeFormatter())
plt.setp(ax.get_yticklabels(), rotation=90, va='center')

image

lukelbd commented 1 year ago

This is not possible with any format keywords yet, but you can do this by manually updating the cartopy gridliner controlled by proplot as shown below.

Note in the latest stable release, this requires accessing the private attribute ax._gridlines_major, but in the next release / in the "dev" version (install with pip install git+https://github.com/proplot-dev/proplot), this can be done using a public, documented property ax.gridlines_major that points to ax._gridlines_major.

import proplot as pplt
fig, axs = pplt.subplots(proj='cyl')
ax = axs[0]
ax._gridlines_major.ylabel_style.update({'rotation': 90})
ax.format(lonlim=[10.1, 10.13],latlim=[30.1,30.13], lonlines=0.01, latlines=0.015,labels=True,)

iTerm2 M3PFXQ tmpe50hg8sm

gepcel commented 1 year ago

Thank you. This is what I want. I'll close this.