Skip to content

y-labels not visible when x-axis inverted #1606

@kadrlica

Description

@kadrlica

Description

It is conventional in astronomy for the longitude coordinate to be inverted such that it increases to the left. Basemap had the handy celestial keyword argument that could be used to invert the direction of increasing longitude (see here). With cartopy, I've been explicitly inverting the x-axis using Axes.invert_xaxis. This seems to work pretty well for most cases; however, the y-axis labels are not longer drawn when the x-axis is inverted. I'm guessing this could have something to do with how the Gridliner determines which labels are visible based on the axes domain:

def _axes_domain(self, nx=None, ny=None):

I haven't tracked down exactly where the problem is yet, but it should be possible to correct with a judicious use of Axes.xaxis_inverted. Below I've added some code demonstrating the issue.

Code to reproduce

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

fig = plt.figure(figsize=(12, 5))
ax1 = fig.add_subplot(1, 2, 1, projection=ccrs.PlateCarree())
ax1.set_title("Regular")
ax1.plot([1,15],[1,15],'-o',transform=ccrs.PlateCarree())
gl = ax1.gridlines(draw_labels=True)

ax2 = fig.add_subplot(1, 2, 2, projection=ccrs.PlateCarree())
ax2.set_title("Inverted")
ax2.plot([1,15],[1,15],'-o',transform=ccrs.PlateCarree())
ax2.invert_xaxis()
gl = ax2.gridlines(draw_labels=True)
plt.savefig('fig1.png')

fig1

Traceback


Full environment definition

Operating system

Mac OS X

Cartopy version

v0.18.0

conda list

alabaster                 0.7.12                     py_0    conda-forge
appnope                   0.1.0           py37hc8dfbb8_1001    conda-forge
astropy                   4.0.1.post1      py37h9bfed18_0    conda-forge
attrs                     19.3.0                     py_0    conda-forge
babel                     2.8.0                      py_0    conda-forge
backcall                  0.1.0                      py_0    conda-forge
basemap                   1.3.0            py37h8ad5b2f_2    conda-forge
bleach                    3.1.5              pyh9f0ad1d_0    conda-forge
boost-cpp                 1.72.0               hdf9ef73_0    conda-forge
brotlipy                  0.7.0           py37h9bfed18_1000    conda-forge
bzip2                     1.0.8                h0b31af3_2    conda-forge
ca-certificates           2020.6.20            hecda079_0    conda-forge
cairo                     1.16.0            hec6a9b0_1003    conda-forge
cartopy                   0.18.0           py37h08e9697_0    conda-forge
certifi                   2020.6.20        py37hc8dfbb8_0    conda-forge
cffi                      1.14.0           py37h356ff06_0    conda-forge
cfitsio                   3.470                hddc9c06_5    conda-forge
chardet                   3.0.4           py37hc8dfbb8_1006    conda-forge
colorama                  0.4.3                    pypi_0    pypi
cryptography              2.9.2            py37he655712_0    conda-forge
curl                      7.69.1               h2d98d24_0    conda-forge
cycler                    0.10.0                     py_2    conda-forge
dbus                      1.13.6               h2f22bb5_0    conda-forge
decorator                 4.4.2                      py_0    conda-forge
defusedxml                0.6.0                      py_0    conda-forge
docutils                  0.16             py37hc8dfbb8_1    conda-forge
entrypoints               0.3             py37hc8dfbb8_1001    conda-forge
ephem                     3.7.7.1          py37h0b31af3_0    conda-forge
expat                     2.2.9                h4a8c4bd_2    conda-forge
fontconfig                2.13.1            h6b1039f_1001    conda-forge
freetype                  2.10.1               h8da9a1a_0    conda-forge
freexl                    1.0.5             h1de35cc_1002    conda-forge
gdal                      3.0.4           py37h08e9697_10    conda-forge
geos                      3.8.1                h4a8c4bd_0    conda-forge
geotiff                   1.6.0                hd8796ba_0    conda-forge
gettext                   0.19.8.1          h46ab8bc_1002    conda-forge
giflib                    5.2.1                h0b31af3_2    conda-forge
glib                      2.64.2               h577aef8_0    conda-forge
hdf4                      4.2.13            h84186c3_1003    conda-forge
hdf5                      1.10.6          nompi_h3e39495_100    conda-forge
healpy                    1.13.0           py37h1cf269a_1    conda-forge
healsparse                1.1.6                    pypi_0    pypi
icu                       64.2                 h6de7cb9_1    conda-forge
idna                      2.9                        py_1    conda-forge
imagesize                 1.2.0                      py_0    conda-forge
importlib-metadata        1.6.0            py37hc8dfbb8_0    conda-forge
importlib_metadata        1.6.0                         0    conda-forge
ipykernel                 5.2.1            py37h43977f1_0    conda-forge
ipython                   7.14.0           py37hc8dfbb8_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                7.5.1                      py_0    conda-forge
jedi                      0.17.0           py37hc8dfbb8_0    conda-forge
jinja2                    2.11.2             pyh9f0ad1d_0    conda-forge
jpeg                      9c                h1de35cc_1001    conda-forge
json-c                    0.13.1            h1de35cc_1001    conda-forge
jsonschema                3.2.0            py37hc8dfbb8_1    conda-forge
jupyter                   1.0.0                      py_2    conda-forge
jupyter_client            6.1.3                      py_0    conda-forge
jupyter_console           6.1.0                      py_1    conda-forge
jupyter_core              4.6.3            py37hc8dfbb8_1    conda-forge
kealib                    1.4.13               h40102fb_1    conda-forge
keyring                   21.2.1                   pypi_0    pypi
kiwisolver                1.2.0            py37ha1cc60f_0    conda-forge
krb5                      1.17.1               h1752a42_0    conda-forge
libblas                   3.8.0               16_openblas    conda-forge
libcblas                  3.8.0               16_openblas    conda-forge
libclang                  9.0.1           default_hf57f61e_0    conda-forge
libcurl                   7.69.1               hc0b9707_0    conda-forge
libcxx                    10.0.0               h1af66ff_2    conda-forge
libdap4                   3.20.6               h8c15375_0    conda-forge
libedit                   3.1.20170329      hcfe32e1_1001    conda-forge
libffi                    3.2.1             h4a8c4bd_1007    conda-forge
libgdal                   3.0.4               h242383b_10    conda-forge
libgfortran               4.0.0                         2    conda-forge
libiconv                  1.15              h0b31af3_1006    conda-forge
libkml                    1.3.0             h169b8f9_1011    conda-forge
liblapack                 3.8.0               16_openblas    conda-forge
libllvm9                  9.0.1                h7475705_1    conda-forge
libnetcdf                 4.7.4           nompi_ha11d67f_104    conda-forge
libopenblas               0.3.9                h3d69b6c_0    conda-forge
libpng                    1.6.37               hbbe82c9_1    conda-forge
libpq                     12.2                 h489d428_1    conda-forge
libsodium                 1.0.17               h01d97ff_0    conda-forge
libspatialite             4.3.0a            h658e6c1_1038    conda-forge
libssh2                   1.8.2                hcdc9a53_2    conda-forge
libtiff                   4.1.0                h2ae36a8_6    conda-forge
libwebp-base              1.1.0                h0b31af3_3    conda-forge
libxml2                   2.9.10               h53d96d6_0    conda-forge
llvm-openmp               10.0.0               h28b9765_0    conda-forge
lz4-c                     1.9.2                h4a8c4bd_1    conda-forge
markupsafe                1.1.1            py37h9bfed18_1    conda-forge
matplotlib                3.2.1                         0    conda-forge
matplotlib-base           3.2.1            py37hddda452_0    conda-forge
mistune                   0.8.4           py37h9bfed18_1001    conda-forge
more-itertools            8.2.0                      py_0    conda-forge
nbconvert                 5.6.1            py37hc8dfbb8_1    conda-forge
nbformat                  5.0.6                      py_0    conda-forge
ncurses                   6.1               h0a44026_1002    conda-forge
nose                      1.3.7           py37hc8dfbb8_1004    conda-forge
notebook                  6.0.3            py37hc8dfbb8_0    conda-forge
nspr                      4.20              h0a44026_1000    conda-forge
nss                       3.47                 hc0980d9_0    conda-forge
numpy                     1.18.4           py37h7687784_0    conda-forge
olefile                   0.46                       py_0    conda-forge
openjpeg                  2.3.1                h254dc36_3    conda-forge
openssl                   1.1.1g               h0b31af3_0    conda-forge
owslib                    0.19.2                     py_1    conda-forge
packaging                 20.1                       py_0    conda-forge
pandas                    1.0.3            py37h94625e5_1    conda-forge
pandoc                    2.9.2.1                       0    conda-forge
pandocfilters             1.4.2                      py_1    conda-forge
parso                     0.7.0              pyh9f0ad1d_0    conda-forge
pcre                      8.44                 h4a8c4bd_0    conda-forge
pexpect                   4.8.0            py37hc8dfbb8_1    conda-forge
pickleshare               0.7.5           py37hc8dfbb8_1001    conda-forge
pillow                    7.1.2            py37hfd78ece_0    conda-forge
pip                       20.1               pyh9f0ad1d_0    conda-forge
pixman                    0.38.0            h01d97ff_1003    conda-forge
pkginfo                   1.5.0.1                  pypi_0    pypi
pluggy                    0.13.1           py37hc8dfbb8_1    conda-forge
poppler                   0.87.0               h3232a60_1    conda-forge
poppler-data              0.4.9                         1    conda-forge
postgresql                12.2                 h62ab893_1    conda-forge
proj                      7.0.0                hbce2d5c_3    conda-forge
prometheus_client         0.7.1                      py_0    conda-forge
prompt-toolkit            3.0.5                      py_0    conda-forge
prompt_toolkit            3.0.5                         0    conda-forge
ptyprocess                0.6.0                   py_1001    conda-forge
py                        1.8.1                      py_0    conda-forge
pycparser                 2.20                       py_0    conda-forge
pyepsg                    0.4.0                      py_0    conda-forge
pygments                  2.6.1                      py_0    conda-forge
pyopenssl                 19.1.0                     py_1    conda-forge
pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
pyproj                    2.6.1.post1      py37hbd4ead9_0    conda-forge
pyqt                      5.12.3           py37ha62fc16_3    conda-forge
pyqt5-sip                 4.19.18                  pypi_0    pypi
pyqtchart                 5.12                     pypi_0    pypi
pyqtwebengine             5.12.1                   pypi_0    pypi
pyrsistent                0.16.0           py37h9bfed18_0    conda-forge
pyshp                     2.1.0                      py_0    conda-forge
pysocks                   1.7.1            py37hc8dfbb8_1    conda-forge
pytest                    5.4.2            py37hc8dfbb8_0    conda-forge
pytest-runner             5.2                        py_0    conda-forge
python                    3.7.6           h90870a6_5_cpython    conda-forge
python-dateutil           2.8.1                      py_0    conda-forge
python_abi                3.7                     1_cp37m    conda-forge
pytz                      2020.1             pyh9f0ad1d_0    conda-forge
pyyaml                    5.3.1            py37h9bfed18_0    conda-forge
pyzmq                     19.0.1           py37haec44b1_0    conda-forge
qt                        5.12.5               h514805e_3    conda-forge
qtconsole                 4.7.3              pyh9f0ad1d_0    conda-forge
qtpy                      1.9.0                      py_0    conda-forge
readline                  8.0                  hcfe32e1_0    conda-forge
readme-renderer           26.0                     pypi_0    pypi
requests                  2.23.0             pyh8c360ce_2    conda-forge
requests-toolbelt         0.9.1                    pypi_0    pypi
rfc3986                   1.4.0                    pypi_0    pypi
scipy                     1.4.1            py37hce1b9e5_3    conda-forge
send2trash                1.5.0                      py_0    conda-forge
setuptools                46.2.0           py37hc8dfbb8_0    conda-forge
shapely                   1.7.0            py37hfcf0db4_3    conda-forge
six                       1.14.0                     py_1    conda-forge
snowballstemmer           2.0.0                      py_0    conda-forge
sphinx                    3.1.1                      py_0    conda-forge
sphinx-rtd-theme          0.5.0                    pypi_0    pypi
sphinxcontrib-applehelp   1.0.2                      py_0    conda-forge
sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
sphinxcontrib-htmlhelp    1.0.3                      py_0    conda-forge
sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
sphinxcontrib-qthelp      1.0.3                      py_0    conda-forge
sphinxcontrib-serializinghtml 1.1.4                      py_0    conda-forge
sqlite                    3.30.1               h93121df_0    conda-forge
tbb                       2018.0.5             h2d50403_0    conda-forge
terminado                 0.8.3            py37hc8dfbb8_1    conda-forge
testpath                  0.4.4                      py_0    conda-forge
tiledb                    1.7.7                h84aa2a7_1    conda-forge
tk                        8.6.10               hbbe82c9_0    conda-forge
tornado                   6.0.4            py37h9bfed18_1    conda-forge
tqdm                      4.47.0                   pypi_0    pypi
traitlets                 4.3.3            py37hc8dfbb8_1    conda-forge
twine                     3.2.0                    pypi_0    pypi
tzcode                    2020a                h0b31af3_0    conda-forge
urllib3                   1.25.9                     py_0    conda-forge
wcwidth                   0.1.9              pyh9f0ad1d_0    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.34.2                     py_1    conda-forge
widgetsnbextension        3.5.1                    py37_0    conda-forge
xerces-c                  3.2.2             h8f8adb3_1004    conda-forge
xz                        5.2.5                h0b31af3_0    conda-forge
yaml                      0.2.4                h0b31af3_0    conda-forge
zeromq                    4.3.2                h6de7cb9_2    conda-forge
zipp                      3.1.0                      py_0    conda-forge
zlib                      1.2.11            h0b31af3_1006    conda-forge
zstd                      1.4.4                h4b3e974_3    conda-forge

pip list

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions