Cartopy does not correctly hide labels set as 'False'
Description
Hi everyone!
I'm very new with Cartopy (I've been using Basemap for a while) and I'm trying to make quite basic stuffs, like choosing a projection and adding lat/lon labels. Things work fine with PlateCarree, but things get weird when I use another projection. I only try to hide top and right labels and here is what I get. I guess this is a bug(?).
Code to reproduce
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 6))
ax = plt.subplot(2,2,1,projection=ccrs.PlateCarree())
gl = ax.gridlines(draw_labels=True)
gl.top_labels = False
gl.right_labels = False
ax = plt.subplot(2,2,2,projection=ccrs.EqualEarth())
gl = ax.gridlines(draw_labels=True)
gl.top_labels = False
gl.right_labels = False
ax = plt.subplot(2,2,3,projection=ccrs.Robinson())
gl = ax.gridlines(draw_labels=True)
gl.top_labels = False
gl.right_labels = False
ax = plt.subplot(2,2,4,projection=ccrs.Mollweide())
gl = ax.gridlines(draw_labels=True)
gl.top_labels = False
gl.right_labels = False
plt.savefig('maps.png')

Full environment definition
Operating system
GNU/Linux 20.04.1-Ubuntu 5.8.0-41-generic x86_64
Cartopy version
Cartopy 0.18.0
conda list
# Name Version Build Channel
_libgcc_mutex 0.1 main
argon2-cffi 20.1.0 py38h7b6447c_1 anaconda
async_generator 1.10 py_0 anaconda
attrs 20.2.0 py_0 anaconda
backcall 0.2.0 py_0 anaconda
blas 1.0 mkl
bleach 3.2.1 py_0 anaconda
brotlipy 0.7.0 py38h27cfd23_1003
bzip2 1.0.8 h7b6447c_0
ca-certificates 2021.1.19 h06a4308_0
cartopy 0.18.0 py38hee755e7_0
certifi 2020.12.5 py38h06a4308_0
cffi 1.14.3 py38h261ae71_2
cftime 1.3.1 py38h6323ea4_0
chardet 3.0.4 py38h06a4308_1003
conda 4.9.2 py38h06a4308_0
conda-package-handling 1.7.2 py38h03888b9_0
cryptography 3.2.1 py38h3c74f83_1
curl 7.71.1 hbc83047_1
cycler 0.10.0 py38_0
dbus 1.13.18 hb2f20db_0 anaconda
decorator 4.4.2 py_0 anaconda
defusedxml 0.6.0 py_0 anaconda
entrypoints 0.3 py38_0 anaconda
expat 2.2.10 he6710b0_2 anaconda
fontconfig 2.13.0 h9420a91_0 anaconda
freetype 2.10.4 h5ab3b9f_0 anaconda
geos 3.8.0 he6710b0_0
glib 2.56.2 hd408876_0 anaconda
gst-plugins-base 1.14.0 hbbd80ab_1 anaconda
gstreamer 1.14.0 hb453b48_1 anaconda
hdf4 4.2.13 h3ca952b_2
hdf5 1.10.4 hb1b8bf9_0
icu 58.2 he6710b0_3 anaconda
idna 2.10 py_0
importlib-metadata 2.0.0 py_1 anaconda
importlib_metadata 2.0.0 1 anaconda
intel-openmp 2020.2 254
ipykernel 5.3.4 py38h5ca1d4c_0 anaconda
ipython 7.19.0 py38hb070fc8_1
ipython_genutils 0.2.0 py38_0 anaconda
ipywidgets 7.5.1 py_1 anaconda
jedi 0.17.2 py38_0 anaconda
jinja2 2.11.2 py_0 anaconda
jpeg 9b habf39ab_1 anaconda
jsonschema 3.2.0 py_2 anaconda
jupyter 1.0.0 py38_7 anaconda
jupyter_client 6.1.7 py_0 anaconda
jupyter_console 6.2.0 py_0 anaconda
jupyter_core 4.6.3 py38_0 anaconda
jupyterlab_pygments 0.1.2 py_0 anaconda
kiwisolver 1.3.0 py38h2531618_0
krb5 1.18.2 h173b8e3_0
lcms2 2.11 h396b838_0
ld_impl_linux-64 2.33.1 h53a641e_7
libcurl 7.71.1 h20c2e04_1
libedit 3.1.20191231 h14c3975_1
libffi 3.3 he6710b0_2
libgcc-ng 9.1.0 hdf63c60_0
libgfortran-ng 7.3.0 hdf63c60_0
libnetcdf 4.7.3 hb80b6cc_0
libpng 1.6.37 hbc83047_0 anaconda
libsodium 1.0.18 h7b6447c_0 anaconda
libssh2 1.9.0 h1ba5d50_1
libstdcxx-ng 9.1.0 hdf63c60_0
libtiff 4.1.0 h2733197_1
libuuid 1.0.3 h1bed415_2 anaconda
libxcb 1.14 h7b6447c_0 anaconda
libxml2 2.9.10 hb55368b_3 anaconda
lz4-c 1.9.3 h2531618_0
markupsafe 1.1.1 py38h7b6447c_0 anaconda
matplotlib 3.3.2 h06a4308_0
matplotlib-base 3.3.2 py38h817c723_0
mistune 0.8.4 py38h7b6447c_1000 anaconda
mkl 2020.2 256
mkl-service 2.3.0 py38he904b0f_0
mkl_fft 1.2.0 py38h23d657b_0
mkl_random 1.1.1 py38h0573a6f_0
nbclient 0.5.1 py_0 anaconda
nbconvert 6.0.7 py38_0 anaconda
nbformat 5.0.8 py_0 anaconda
ncurses 6.2 he6710b0_1
nest-asyncio 1.4.1 py_0 anaconda
netcdf4 1.5.3 py38hbf33ddf_0
notebook 6.1.4 py38_0 anaconda
numpy 1.19.2 py38h54aff64_0
numpy-base 1.19.2 py38hfa32c7d_0
olefile 0.46 py_0
openssl 1.1.1i h27cfd23_0
owslib 0.22.0 pyhd3eb1b0_0
packaging 20.4 py_0 anaconda
pandas 1.2.1 py38ha9443f7_0
pandoc 2.11 hb0f4dca_0 anaconda
pandocfilters 1.4.2 py38_1 anaconda
parso 0.7.0 py_0 anaconda
pcre 8.44 he6710b0_0 anaconda
pexpect 4.8.0 py38_0 anaconda
pickleshare 0.7.5 py38_1000 anaconda
pillow 8.1.0 py38he98fc37_0
pip 20.2.4 py38h06a4308_0
proj 6.2.1 haa6030c_0
prometheus_client 0.8.0 py_0 anaconda
prompt-toolkit 3.0.8 py_0 anaconda
prompt_toolkit 3.0.8 0 anaconda
ptyprocess 0.6.0 py38_0 anaconda
pycosat 0.6.3 py38h7b6447c_1
pycparser 2.20 py_2
pyepsg 0.4.0 py_0
pygments 2.7.1 py_0 anaconda
pykdtree 1.3.1 py38hdd07704_1002
pyopenssl 19.1.0 pyhd3eb1b0_1
pyparsing 2.4.7 py_0 anaconda
pyproj 2.6.1.post1 py38hd003209_1
pyqt 5.9.2 py38h05f1152_4 anaconda
pyrsistent 0.17.3 py38h7b6447c_0 anaconda
pyshp 2.1.3 pyhd3eb1b0_0
pysocks 1.7.1 py38h06a4308_0
python 3.8.5 h7579374_1
python-dateutil 2.8.1 py_0 anaconda
pytz 2020.5 pyhd3eb1b0_0
pyyaml 5.4.1 py38h27cfd23_1
pyzmq 19.0.2 py38he6710b0_1 anaconda
qt 5.9.7 h5867ecd_1 anaconda
qtconsole 4.7.7 py_0 anaconda
qtpy 1.9.0 py_0 anaconda
readline 8.0 h7b6447c_0
requests 2.24.0 py_0
ruamel_yaml 0.15.87 py38h7b6447c_1
scipy 1.5.2 py38h0b6359f_0
seaborn 0.11.1 pyhd3eb1b0_0
send2trash 1.5.0 py38_0 anaconda
setuptools 50.3.1 py38h06a4308_1
shapely 1.7.1 py38h98ec03d_0
sip 4.19.24 py38he6710b0_0 anaconda
six 1.15.0 py38h06a4308_0
sqlite 3.33.0 h62c20be_0
terminado 0.9.1 py38_0 anaconda
testpath 0.4.4 py_0 anaconda
tk 8.6.10 hbc83047_0
tornado 6.0.4 py38h7b6447c_1 anaconda
tqdm 4.51.0 pyhd3eb1b0_0
traitlets 5.0.5 py_0 anaconda
urllib3 1.25.11 py_0
wcwidth 0.2.5 py_0 anaconda
webencodings 0.5.1 py38_1 anaconda
wheel 0.35.1 pyhd3eb1b0_0
widgetsnbextension 3.5.1 py38_0 anaconda
xarray 0.16.2 pyhd3eb1b0_0
xz 5.2.5 h7b6447c_0
yaml 0.2.5 h7b6447c_0
zeromq 4.3.3 he6710b0_3 anaconda
zipp 3.3.1 py_0 anaconda
zlib 1.2.11 h7b6447c_3
zstd 1.4.5 h9ceee32_0
pip list
Package Version
---------------------- -------------------
argon2-cffi 20.1.0
async-generator 1.10
attrs 20.2.0
backcall 0.2.0
bleach 3.2.1
brotlipy 0.7.0
Cartopy 0.18.0
certifi 2020.12.5
cffi 1.14.3
cftime 1.3.1
chardet 3.0.4
conda 4.9.2
conda-package-handling 1.7.2
cryptography 3.2.1
cycler 0.10.0
decorator 4.4.2
defusedxml 0.6.0
entrypoints 0.3
idna 2.10
importlib-metadata 2.0.0
ipykernel 5.3.4
ipython 7.19.0
ipython-genutils 0.2.0
ipywidgets 7.5.1
jedi 0.17.2
Jinja2 2.11.2
jsonschema 3.2.0
jupyter 1.0.0
jupyter-client 6.1.7
jupyter-console 6.2.0
jupyter-core 4.6.3
jupyterlab-pygments 0.1.2
kiwisolver 1.3.0
MarkupSafe 1.1.1
matplotlib 3.3.2
mistune 0.8.4
mkl-fft 1.2.0
mkl-random 1.1.1
mkl-service 2.3.0
nbclient 0.5.1
nbconvert 6.0.7
nbformat 5.0.8
nest-asyncio 1.4.1
netCDF4 1.5.3
notebook 6.1.4
numpy 1.19.2
olefile 0.46
OWSLib 0.22.0
packaging 20.4
pandas 1.2.1
pandocfilters 1.4.2
parso 0.7.0
pexpect 4.8.0
pickleshare 0.7.5
Pillow 8.1.0
pip 20.2.4
prometheus-client 0.8.0
prompt-toolkit 3.0.8
ptyprocess 0.6.0
pycosat 0.6.3
pycparser 2.20
pyepsg 0.4.0
Pygments 2.7.1
pykdtree 1.3.1
pyOpenSSL 19.1.0
pyparsing 2.4.7
pyproj 2.6.1.post1
pyrsistent 0.17.3
pyshp 2.1.3
PySocks 1.7.1
python-dateutil 2.8.1
pytz 2020.5
PyYAML 5.4.1
pyzmq 19.0.2
qtconsole 4.7.7
QtPy 1.9.0
requests 2.24.0
ruamel-yaml 0.15.87
scipy 1.5.2
seaborn 0.11.1
Send2Trash 1.5.0
setuptools 50.3.1.post20201107
Shapely 1.7.1
sip 4.19.24
six 1.15.0
terminado 0.9.1
testpath 0.4.4
tornado 6.0.4
tqdm 4.51.0
traitlets 5.0.5
urllib3 1.25.11
wcwidth 0.2.5
webencodings 0.5.1
wheel 0.35.1
widgetsnbextension 3.5.1
xarray 0.16.2
zipp 3.3.1
Maybe the same question as #1714? It can be solved by PR #1537.
Yes, it looks very similar. I'm quite new with github too and I'm not sure to understand what you mean by "It can be solved by PR #1537.". Do you mean there is a solution there that I can use or do you mean the problem has been fixed but I'll need to wait for the release of the next Cartopy version to use it? Thanks!
I mean it is solved by that PR, but that PR has not been merged yet. In the next release (v0.19), which is planned in next week (or two weeks, see #1703), this PR may not be included. So you have to wait for a longer time for that to be released. An alternative is to directly install that PR by yourself (not recommended).
Looks good! Many thanks for the explanation!!
Thanks for the information, @smartlixx.
I've also been dealing with this issue for some time now. Hopefully, #1537 will make it into #1703!
Closed by #1537
Why is this closed when this is still a problem?
Version 20.2, Robinson, and other projections, have multiple bugs. I try to get around it by grabbing the label positions and then manually decide what labels to draw ..
If you do Robinson and draw_labels=True, it will draw all labels. But right_label_artists and left will only have the first two instances of labels. This is independent of if you use ylocs or just default ... so now my work around the bug doesn't even work. Why is gridlines still so buggy?
You should probably give a precise example to reproduce your problem.
Note that all labels that are attached to a GeoSpine, that is to say to the map boundary and not on the left, right, top and bottom spines, are available in the geo_label_artists gridliner attribute. Note that you can control which labels will be traced almost entirely with the keyword draw_labels which accept rich values (see the doc).
A notebook should probably be written to expose all capabilities of the gridliner to optimize its usage. If somebody wants to contribute... Would you?
Dear sir, I got crazy by the labels of cartopy. I wanted to show the only bottom and left labels, on the projection of EckertIII. But this will always show the top labels. ` fig = plt.figure(figsize=(16, 8)) # Setup a global EckertIII map with faint coastlines # ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree()) ax = fig.add_subplot(1,1,1, projection=ccrs.EckertIII()) x = np.arange(-90, 90) y = x.copy() x2, y2 = np.meshgrid(x, y) z = x2*y2 filled_c = ax.contourf(x2, y2, z, transform=ccrs.PlateCarree()) line_c = ax.contour(x2, y2, z, levels=filled_c.levels, colors=['black'], transform=ccrs.PlateCarree()) plt.colorbar(filled_c, orientation='vertical', ax=ax) ax.set_global() ax.coastlines('50m', alpha=0.2, color='k') # Use the line contours to place contour labels ax.clabel( line_c, # Typically best results when labelling line contours colors=['black'], manual=False, # Automatic placement vs manual placement inline=True, # Cut the line where the label will be placed fmt=' {:.0f} '.format, # Labes as integers, with some extra space ) gl = ax.gridlines(color='k', linestyle='--', lw=0.5, draw_labels=["x", "bottom", "left"])
gl.xlabel_style = dict(fontsize=8)
gl.ylabel_style = dict(fontsize=8, rotation=90, va='bottom', ha='center')
gl.right_labels = False
gl = ax.gridlines(color='k', linestyle='--', lw=0.5, draw_labels=["x", "bottom", "left"])
gl.rotate_labels = False
gl.xlabel_style = dict(fontsize=8)
gl.ylabel_style = dict(fontsize=8, rotation=90, va='bottom', ha='center')
gl.top_labels = False
`

This is still not fixed in version = 0.23.0 as far as I can tell.
my score is not updated on friend's game as well. the screenshot below was taken few min ago by my friend.
This issue is stale because it has been open for 365 days with no activity.
This issue was closed because it has been inactive for 90 days since being marked as stale.