This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hello! Thanks for reaching out.
Without seeing your original code, I can't be totally sure why this isn't
working from you. It likely depends on how you are drawing the lines and
labels. The following code will generate the attached plot on Cartopy 0.20.2.
The version here is important, as some of the syntax for controlling line and
label location and formatting has changed, so be sure to update if you aren't
already!
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
# plt.subplots useful for quickly creating both an axes
# and containing figure, with keywords specified up-front
f, ax = plt.subplots(figsize=(12, 8), subplot_kw={"projection":
ccrs.Robinson()})
ax.coastlines()
gl = ax.gridlines(draw_labels=True)
gl.xlines = False
gl.ylocator = mticker.FixedLocator(
[-80, -70, -60, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70,
80]
)
gl.top_labels = False
gl.bottom_labels = False
f.savefig("test.png") # tested on 300 dpi too
Importantly, creating the `gridlines` object with labels drawn will give you
more control over gridline location and labelling. Your issue with figure
drawing may depend on default font/line sizes and a figure that is too small
such that labels get overridden. You'll see in this example that I specified a
figure size. Give this a try yourself and let me know if that fixes your figure
drawing issue! If not, please be sure to follow up and attach your full code
and the associated output. Hope this helps.
All the best,
Drew
> We will be very grateful to you if you can show us an example on labeling
> the latitude axis on following latitudes, say,
> [-80, -70, -60, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80]
> on a cartopy map with Robinson projection (without label rotation).
>
> We have found two issues here:
> 1) There are missing labels for latitudes north and south of 50 degrees;
> 2) The figure seen from plt.show() on jupyter notebook is not the same when
> the figure is saved with fig.savefig('fig.png', dpi=300). Only a label of
> equator 0 can be found on the saved png file.
>
Ticket Details
===================
Ticket ID: SVF-637421
Department: Support Python
Priority: Low
Status: Closed
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata
inquiry tracking system and then made publicly available through the web. If
you do not want to have your interactions made available in this way, you must
let us know in each email you send to us.
Attachment:
test.png
Description: PNG image