proplot-dev / proplot

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

GeoAxes features request #397

Closed Dearsomeone closed 1 year ago

Dearsomeone commented 1 year ago

Description

Hello, I am a regular user of proplot with which I can draw beautiful geoscience plots. CartesianAxes provides powerful contol on axes major and minor ticks. But for GeoAxes, it seems that proplot only provides control of lat and lon grid lines. If I want to show lat and lon ticks for NCL style geographic plots, I can only call the matplotlib method ax.tick_params(). As shown below, the code will become redundant and inconsistent with the proplot style. If the GeoAxes.format can control the lat and lon ticks, I think it will be a nice feature.

Steps to reproduce

# your code here
# we should be able to copy-paste this into python and exactly reproduce your bug
import proplot as pplt
import cartopy.crs as ccrs
import matplotlib.ticker as ticker
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter

fig = pplt.figure(refwidth=5)

axs = fig.subplots(nrows=1, ncols=1, proj="cyl", proj_kw={"lon_0": 200}, right="3em")

axs.format(
    suptitle="Figure with NCL sytle by matplotlib",
    suptitlesize=12,
    suptitlepad=10,
    land=True,
    landcolor="k",
    coast=True,
    coastlinewidth=1,
    reso="lo",
    latlim=(-90, 90),
    lonlim=(0, 360),
    grid=False,
)

axs.set_xticks(np.arange(0, 381, 60), crs=ccrs.PlateCarree())
axs.set_yticks(np.arange(-90, 91, 30), crs=ccrs.PlateCarree())

lon_formatter = LongitudeFormatter(zero_direction_label=False)
lat_formatter = LatitudeFormatter()
axs.xaxis.set_major_formatter(lon_formatter)
axs.yaxis.set_major_formatter(lat_formatter)

axs.xaxis.set_tick_params(labelsize=10, pad=5)
axs.yaxis.set_tick_params(labelsize=10, pad=5)

axs.xaxis.set_minor_locator(ticker.IndexLocator(base=30, offset=10))
axs.yaxis.set_minor_locator(ticker.MultipleLocator(15))

axs.tick_params(
    which="major",
    direction="out",
    length=10,
    width=1.5,
    colors="k",
    top="on",
    bottom="on",
    left="on",
    right="on",
)

axs.tick_params(
    which="minor",
    direction="out",
    length=5,
    width=0.8,
    top="on",
    bottom="on",
    left="on",
    right="on",
)

axs.grid(False)

Expected behavior: image

Proplot version

matplotlib.version = 3.2.2 proplot.version = 0.9.5

lukelbd commented 1 year ago

Thanks for the demo / explanation. Agree this would be really useful. Looks like there's an older thread on this topic (#227), and an unmerged PR (#253) -- further discussion should go there.