2
votes

I am drawing the map above using cartopy and the foll. code:

gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, alpha=0.35)
gl.xlabels_top = False
gl.ylabels_left = False
gl.xlocator = mticker.FixedLocator([-120, -60, 0, 60, 120])
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER

How do I restrict this to only draw gridlines for -23.5 N, 0 and 23.5 degree N latitude?

1
Try: gl.ylocator = mticker.FixedLocator([-23.5, 23.5]) - Maciej A. Czyzewski
I did, it does not work. It still draws the latitude lines PLUS the 2 new ones i.e. -23.5 and 23.5 - user308827
I see... try to remove all ticks matplotlib.org/api/…, like: gl.gca().yaxis.set_major_locator(gl.NullLocator()) - Maciej A. Czyzewski
I get this error AttributeError: 'GeoAxesSubplot' object has no attribute 'gca' - user308827
The function gca() returns the current axes, try simply without. - Maciej A. Czyzewski

1 Answers

1
votes

You could try gl.set_xlim(-23.5, 23.5), otherwise you are only changing where the tick marks appear rather than where your axes start and stop.