Home > Net >  Cartopy: show tick marks of axes
Cartopy: show tick marks of axes

Time:10-07

I want to show axes tick marks outside. Cartopy removes axes tick marks!. I tried the solution enter image description here

CodePudding user response:

You can add tick marks to the plot using matplotlib set_xticks with the relevant crs. Then add gridlines separately

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

from cartopy.mpl.ticker import (LongitudeFormatter, LatitudeFormatter,
                                LatitudeLocator, LongitudeLocator)

fig, ax = plt.subplots(figsize=(10, 5), subplot_kw={"projection":ccrs.PlateCarree()})

ax.coastlines()

ax.yaxis.tick_right()
ax.set_xticks([-180,-120, -60, 0, 60, 120, 180], crs=ccrs.PlateCarree())
ax.set_yticks([-90, -60, -30, 0, 30, 60, 90], crs=ccrs.PlateCarree())
lon_formatter = LongitudeFormatter(zero_direction_label=True)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)

gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False,
                  linewidth=2, color='gray', alpha=0.5, linestyle='--')

Based on cartopy global PlateCarree map with tick marks and grid lines

  • Related