Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeoAxes._update_title_position called before Gridliner._labels is populated #2390

Closed
trexfeathers opened this issue May 23, 2024 · 7 comments · Fixed by #2393
Closed

GeoAxes._update_title_position called before Gridliner._labels is populated #2390

trexfeathers opened this issue May 23, 2024 · 7 comments · Fixed by #2393

Comments

@trexfeathers
Copy link
Contributor

Description

The changes in Cartopy 0.23 mean that plot titles are no longer re-positioned around axis labels.

I have looked into this and it seems to be because Artist._draw_gridliner is no longer called within GeoAxes._draw_preprocess, meaning that no labels are present when GeoAxes._update_title_position is called. See the workaround demonstration below for my hacky fix. Interestingly it does behave correctly if a second save call is made using the same figure.

Code to reproduce

Bug demonstration

hidden_title

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

axes = plt.axes(projection=ccrs.PlateCarree())
axes.gridlines(draw_labels=True)
axes.set_title("MY TITLE")
plt.savefig("hidden_title.png")
Workaround demonstration

visible_title

from cartopy import crs as ccrs
import cartopy.mpl.geoaxes
from matplotlib import pyplot as plt


class MyGeoAxes(cartopy.mpl.geoaxes.GeoAxes):
    def _draw_preprocess(self, renderer):
        super()._draw_preprocess(renderer)

        for artist in self.artists:
            if hasattr(artist, "_draw_gridliner"):
                artist._draw_gridliner(renderer=renderer)


cartopy.mpl.geoaxes.GeoAxes = MyGeoAxes


axes = plt.axes(projection=ccrs.PlateCarree())
axes.gridlines(draw_labels=True)
axes.set_title("MY TITLE")
plt.savefig("visible_title.png")
Full environment definition

Operating system

RHEL7

Cartopy version

0.23

conda list

# packages in environment at /tmp/persistent/conda/envs/sphinx16:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    https://conda.anaconda.org/conda-forge
_openmp_mutex             4.5                       2_gnu    https://conda.anaconda.org/conda-forge
accessible-pygments       0.0.4              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
aiohttp                   3.9.5           py312h98912ed_0    https://conda.anaconda.org/conda-forge
aiosignal                 1.3.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
alabaster                 0.7.16             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
alsa-lib                  1.2.11               hd590300_1    https://conda.anaconda.org/conda-forge
antlr-python-runtime      4.11.1             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
aom                       3.9.0                hac33072_0    https://conda.anaconda.org/conda-forge
asv_runner                0.2.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
atk-1.0                   2.38.0               h04ea711_2    https://conda.anaconda.org/conda-forge
attr                      2.5.1                h166bdaf_1    https://conda.anaconda.org/conda-forge
attrs                     23.2.0             pyh71513ae_0    https://conda.anaconda.org/conda-forge
babel                     2.14.0             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
beautifulsoup4            4.12.3             pyha770c72_0    https://conda.anaconda.org/conda-forge
blosc                     1.21.5               hc2324a3_1    https://conda.anaconda.org/conda-forge
brotli                    1.1.0                hd590300_1    https://conda.anaconda.org/conda-forge
brotli-bin                1.1.0                hd590300_1    https://conda.anaconda.org/conda-forge
brotli-python             1.1.0           py312h30efb56_1    https://conda.anaconda.org/conda-forge
bzip2                     1.0.8                hd590300_5    https://conda.anaconda.org/conda-forge
c-ares                    1.28.1               hd590300_0    https://conda.anaconda.org/conda-forge
ca-certificates           2024.2.2             hbcca054_0    https://conda.anaconda.org/conda-forge
cairo                     1.18.0               h3faef2a_0    https://conda.anaconda.org/conda-forge
cartopy                   0.23.0          py312hfb8ada1_0    https://conda.anaconda.org/conda-forge
certifi                   2024.2.2           pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
cf-units                  3.2.0           py312hc7c0aa3_4    https://conda.anaconda.org/conda-forge
cffi                      1.16.0          py312hf06ca03_0    https://conda.anaconda.org/conda-forge
cfgv                      3.3.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
cftime                    1.6.3           py312hc7c0aa3_0    https://conda.anaconda.org/conda-forge
charset-normalizer        3.3.2              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
click                     8.1.7           unix_pyh707e725_0    https://conda.anaconda.org/conda-forge
click-default-group       1.2.4              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
cloudpickle               3.0.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
cmocean                   4.0.3              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
colorcet                  3.1.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
colorspacious             1.1.2              pyh24bf2e0_0    https://conda.anaconda.org/conda-forge
contourpy                 1.2.1           py312h8572e83_0    https://conda.anaconda.org/conda-forge
coverage                  7.5.1           py312h9a8786e_0    https://conda.anaconda.org/conda-forge
cycler                    0.12.1             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
cython                    3.0.10          py312h30efb56_0    https://conda.anaconda.org/conda-forge
cytoolz                   0.12.3          py312h98912ed_0    https://conda.anaconda.org/conda-forge
dask-core                 2024.5.0           pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
dav1d                     1.2.1                hd590300_0    https://conda.anaconda.org/conda-forge
dbus                      1.13.6               h5008d03_3    https://conda.anaconda.org/conda-forge
distlib                   0.3.8              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
distributed               2024.5.0           pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
docutils                  0.21.2             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
double-conversion         3.3.0                h59595ed_0    https://conda.anaconda.org/conda-forge
eigen                     3.4.0                h00ab1b0_0    https://conda.anaconda.org/conda-forge
esmf                      8.6.1           nompi_h7b237b1_0    https://conda.anaconda.org/conda-forge
esmpy                     8.6.1              pyhc1e730c_0    https://conda.anaconda.org/conda-forge
exceptiongroup            1.2.0              pyhd8ed1ab_2    https://conda.anaconda.org/conda-forge
execnet                   2.1.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
expat                     2.5.0                hcb278e6_1    https://conda.anaconda.org/conda-forge
ffmpeg                    6.1.1           gpl_h1a7fc40_111    https://conda.anaconda.org/conda-forge
filelock                  3.14.0             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    https://conda.anaconda.org/conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    https://conda.anaconda.org/conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    https://conda.anaconda.org/conda-forge
font-ttf-ubuntu           0.83                 h77eed37_2    https://conda.anaconda.org/conda-forge
fontconfig                2.14.2               h14ed4e7_0    https://conda.anaconda.org/conda-forge
fonts-conda-ecosystem     1                             0    https://conda.anaconda.org/conda-forge
fonts-conda-forge         1                             0    https://conda.anaconda.org/conda-forge
fonttools                 4.51.0          py312h98912ed_0    https://conda.anaconda.org/conda-forge
freetype                  2.12.1               h267a509_2    https://conda.anaconda.org/conda-forge
fribidi                   1.0.10               h36c2ea0_0    https://conda.anaconda.org/conda-forge
frozenlist                1.4.1           py312h98912ed_0    https://conda.anaconda.org/conda-forge
fsspec                    2024.3.1           pyhca7485f_0    https://conda.anaconda.org/conda-forge
gdk-pixbuf                2.42.11              hb9ae30d_0    https://conda.anaconda.org/conda-forge
geos                      3.12.1               h59595ed_0    https://conda.anaconda.org/conda-forge
geovista                  0.4.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
gettext                   0.22.5               h59595ed_2    https://conda.anaconda.org/conda-forge
gettext-tools             0.22.5               h59595ed_2    https://conda.anaconda.org/conda-forge
giflib                    5.2.2                hd590300_0    https://conda.anaconda.org/conda-forge
gl2ps                     1.4.2                h0708190_0    https://conda.anaconda.org/conda-forge
glew                      2.1.0                h9c3ff4c_2    https://conda.anaconda.org/conda-forge
glib                      2.80.2               hf974151_0    https://conda.anaconda.org/conda-forge
glib-tools                2.80.2               hb6ce0ca_0    https://conda.anaconda.org/conda-forge
gmp                       6.3.0                h59595ed_1    https://conda.anaconda.org/conda-forge
gnutls                    3.7.9                hb077bed_0    https://conda.anaconda.org/conda-forge
graphite2                 1.3.13            h59595ed_1003    https://conda.anaconda.org/conda-forge
graphviz                  9.0.0                h78e8752_1    https://conda.anaconda.org/conda-forge
gst-plugins-base          1.22.9               h8e1006c_0    https://conda.anaconda.org/conda-forge
gstreamer                 1.22.9               h98fc4e7_0    https://conda.anaconda.org/conda-forge
gtk2                      2.24.33              h280cfa0_4    https://conda.anaconda.org/conda-forge
gts                       0.7.6                h977cf35_4    https://conda.anaconda.org/conda-forge
harfbuzz                  8.4.0                h3d44ed6_0    https://conda.anaconda.org/conda-forge
hdf4                      4.2.15               h2a13503_7    https://conda.anaconda.org/conda-forge
hdf5                      1.14.3          nompi_h4f84152_101    https://conda.anaconda.org/conda-forge
icu                       73.2                 h59595ed_0    https://conda.anaconda.org/conda-forge
identify                  2.5.36             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
idna                      3.7                pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
imagehash                 4.3.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
imagesize                 1.4.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
importlib-metadata        7.1.0              pyha770c72_0    https://conda.anaconda.org/conda-forge
importlib_metadata        7.1.0                hd8ed1ab_0    https://conda.anaconda.org/conda-forge
iniconfig                 2.0.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
iris-sample-data          2.4.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
jinja2                    3.1.4              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
jsoncpp                   1.9.5                h4bd325d_1    https://conda.anaconda.org/conda-forge
keyutils                  1.6.1                h166bdaf_0    https://conda.anaconda.org/conda-forge
kiwisolver                1.4.5           py312h8572e83_1    https://conda.anaconda.org/conda-forge
krb5                      1.21.2               h659d440_0    https://conda.anaconda.org/conda-forge
lame                      3.100             h166bdaf_1003    https://conda.anaconda.org/conda-forge
lcms2                     2.16                 hb7c19ff_0    https://conda.anaconda.org/conda-forge
ld_impl_linux-64          2.40                 h55db66e_0    https://conda.anaconda.org/conda-forge
lerc                      4.0.0                h27087fc_0    https://conda.anaconda.org/conda-forge
libabseil                 20240116.2      cxx17_h59595ed_0    https://conda.anaconda.org/conda-forge
libaec                    1.1.3                h59595ed_0    https://conda.anaconda.org/conda-forge
libasprintf               0.22.5               h661eb56_2    https://conda.anaconda.org/conda-forge
libasprintf-devel         0.22.5               h661eb56_2    https://conda.anaconda.org/conda-forge
libass                    0.17.1               h8fe9dca_1    https://conda.anaconda.org/conda-forge
libblas                   3.9.0           22_linux64_openblas    https://conda.anaconda.org/conda-forge
libbrotlicommon           1.1.0                hd590300_1    https://conda.anaconda.org/conda-forge
libbrotlidec              1.1.0                hd590300_1    https://conda.anaconda.org/conda-forge
libbrotlienc              1.1.0                hd590300_1    https://conda.anaconda.org/conda-forge
libcap                    2.69                 h0f662aa_0    https://conda.anaconda.org/conda-forge
libcblas                  3.9.0           22_linux64_openblas    https://conda.anaconda.org/conda-forge
libclang                  15.0.7          default_h127d8a8_5    https://conda.anaconda.org/conda-forge
libclang13                15.0.7          default_h5d6823c_5    https://conda.anaconda.org/conda-forge
libcups                   2.3.3                h4637d8d_4    https://conda.anaconda.org/conda-forge
libcurl                   8.7.1                hca28451_0    https://conda.anaconda.org/conda-forge
libdeflate                1.20                 hd590300_0    https://conda.anaconda.org/conda-forge
libdrm                    2.4.120              hd590300_0    https://conda.anaconda.org/conda-forge
libedit                   3.1.20191231         he28a2e2_2    https://conda.anaconda.org/conda-forge
libev                     4.33                 hd590300_2    https://conda.anaconda.org/conda-forge
libevent                  2.1.12               hf998b51_1    https://conda.anaconda.org/conda-forge
libexpat                  2.5.0                hcb278e6_1    https://conda.anaconda.org/conda-forge
libffi                    3.4.2                h7f98852_5    https://conda.anaconda.org/conda-forge
libflac                   1.4.3                h59595ed_0    https://conda.anaconda.org/conda-forge
libgcc-ng                 13.2.0               h77fa898_7    https://conda.anaconda.org/conda-forge
libgcrypt                 1.10.3               hd590300_0    https://conda.anaconda.org/conda-forge
libgd                     2.3.3                h119a65a_9    https://conda.anaconda.org/conda-forge
libgettextpo              0.22.5               h59595ed_2    https://conda.anaconda.org/conda-forge
libgettextpo-devel        0.22.5               h59595ed_2    https://conda.anaconda.org/conda-forge
libgfortran-ng            13.2.0               h69a702a_7    https://conda.anaconda.org/conda-forge
libgfortran5              13.2.0               hca663fb_7    https://conda.anaconda.org/conda-forge
libglib                   2.80.2               hf974151_0    https://conda.anaconda.org/conda-forge
libglu                    9.0.0             hac7e632_1003    https://conda.anaconda.org/conda-forge
libgomp                   13.2.0               h77fa898_7    https://conda.anaconda.org/conda-forge
libgpg-error              1.49                 h4f305b6_0    https://conda.anaconda.org/conda-forge
libhwloc                  2.10.0          default_h2fb2949_1000    https://conda.anaconda.org/conda-forge
libiconv                  1.17                 hd590300_2    https://conda.anaconda.org/conda-forge
libidn2                   2.3.7                hd590300_0    https://conda.anaconda.org/conda-forge
libjpeg-turbo             3.0.0                hd590300_1    https://conda.anaconda.org/conda-forge
liblapack                 3.9.0           22_linux64_openblas    https://conda.anaconda.org/conda-forge
libllvm15                 15.0.7               hb3ce162_4    https://conda.anaconda.org/conda-forge
libmo_unpack              3.1.2             hf484d3e_1001    https://conda.anaconda.org/conda-forge
libnetcdf                 4.9.2           nompi_h9612171_113    https://conda.anaconda.org/conda-forge
libnghttp2                1.58.0               h47da74e_1    https://conda.anaconda.org/conda-forge
libnsl                    2.0.1                hd590300_0    https://conda.anaconda.org/conda-forge
libogg                    1.3.4                h7f98852_1    https://conda.anaconda.org/conda-forge
libopenblas               0.3.27          pthreads_h413a1c8_0    https://conda.anaconda.org/conda-forge
libopenvino               2024.1.0             h2da1b83_5    https://conda.anaconda.org/conda-forge
libopenvino-auto-batch-plugin 2024.1.0             hb045406_5    https://conda.anaconda.org/conda-forge
libopenvino-auto-plugin   2024.1.0             hb045406_5    https://conda.anaconda.org/conda-forge
libopenvino-hetero-plugin 2024.1.0             h5c03a75_5    https://conda.anaconda.org/conda-forge
libopenvino-intel-cpu-plugin 2024.1.0             h2da1b83_5    https://conda.anaconda.org/conda-forge
libopenvino-intel-gpu-plugin 2024.1.0             h2da1b83_5    https://conda.anaconda.org/conda-forge
libopenvino-intel-npu-plugin 2024.1.0             he02047a_5    https://conda.anaconda.org/conda-forge
libopenvino-ir-frontend   2024.1.0             h5c03a75_5    https://conda.anaconda.org/conda-forge
libopenvino-onnx-frontend 2024.1.0             h07e8aee_5    https://conda.anaconda.org/conda-forge
libopenvino-paddle-frontend 2024.1.0             h07e8aee_5    https://conda.anaconda.org/conda-forge
libopenvino-pytorch-frontend 2024.1.0             he02047a_5    https://conda.anaconda.org/conda-forge
libopenvino-tensorflow-frontend 2024.1.0             h39126c6_5    https://conda.anaconda.org/conda-forge
libopenvino-tensorflow-lite-frontend 2024.1.0             he02047a_5    https://conda.anaconda.org/conda-forge
libopus                   1.3.1                h7f98852_1    https://conda.anaconda.org/conda-forge
libpciaccess              0.18                 hd590300_0    https://conda.anaconda.org/conda-forge
libpng                    1.6.43               h2797004_0    https://conda.anaconda.org/conda-forge
libpq                     16.3                 ha72fbe1_0    https://conda.anaconda.org/conda-forge
libprotobuf               4.25.3               h08a7969_0    https://conda.anaconda.org/conda-forge
librsvg                   2.58.0               hadf69e7_1    https://conda.anaconda.org/conda-forge
libsndfile                1.2.2                hc60ed4a_1    https://conda.anaconda.org/conda-forge
libsqlite                 3.45.3               h2797004_0    https://conda.anaconda.org/conda-forge
libssh2                   1.11.0               h0841786_0    https://conda.anaconda.org/conda-forge
libstdcxx-ng              13.2.0               hc0a3c3a_7    https://conda.anaconda.org/conda-forge
libsystemd0               255                  h3516f8a_1    https://conda.anaconda.org/conda-forge
libtasn1                  4.19.0               h166bdaf_0    https://conda.anaconda.org/conda-forge
libtheora                 1.1.1             h7f98852_1005    https://conda.anaconda.org/conda-forge
libtiff                   4.6.0                h1dd3fc0_3    https://conda.anaconda.org/conda-forge
libudunits2               2.2.28               h40f5838_3    https://conda.anaconda.org/conda-forge
libunistring              0.9.10               h7f98852_0    https://conda.anaconda.org/conda-forge
libuuid                   2.38.1               h0b41bf4_0    https://conda.anaconda.org/conda-forge
libva                     2.21.0               hd590300_0    https://conda.anaconda.org/conda-forge
libvorbis                 1.3.7                h9c3ff4c_0    https://conda.anaconda.org/conda-forge
libvpx                    1.14.0               h59595ed_0    https://conda.anaconda.org/conda-forge
libwebp                   1.4.0                h2c329e2_0    https://conda.anaconda.org/conda-forge
libwebp-base              1.4.0                hd590300_0    https://conda.anaconda.org/conda-forge
libxcb                    1.15                 h0b41bf4_0    https://conda.anaconda.org/conda-forge
libxcrypt                 4.4.36               hd590300_1    https://conda.anaconda.org/conda-forge
libxkbcommon              1.7.0                h662e7e4_0    https://conda.anaconda.org/conda-forge
libxml2                   2.12.6               h232c23b_2    https://conda.anaconda.org/conda-forge
libzip                    1.10.1               h2629f0a_3    https://conda.anaconda.org/conda-forge
libzlib                   1.2.13               hd590300_5    https://conda.anaconda.org/conda-forge
locket                    1.0.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
loguru                    0.7.2           py312h7900ff3_1    https://conda.anaconda.org/conda-forge
lz4-c                     1.9.4                hcb278e6_0    https://conda.anaconda.org/conda-forge
markupsafe                2.1.5           py312h98912ed_0    https://conda.anaconda.org/conda-forge
matplotlib-base           3.8.4           py312he5832f3_0    https://conda.anaconda.org/conda-forge
mo_pack                   0.3.0           py312h98912ed_1    https://conda.anaconda.org/conda-forge
mpg123                    1.32.6               h59595ed_0    https://conda.anaconda.org/conda-forge
msgpack-python            1.0.7           py312h8572e83_0    https://conda.anaconda.org/conda-forge
multidict                 6.0.5           py312h98912ed_0    https://conda.anaconda.org/conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    https://conda.anaconda.org/conda-forge
mysql-common              8.0.33               hf1915f5_6    https://conda.anaconda.org/conda-forge
mysql-libs                8.0.33               hca2cd23_6    https://conda.anaconda.org/conda-forge
nc-time-axis              1.4.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
ncurses                   6.5                  h59595ed_0    https://conda.anaconda.org/conda-forge
netcdf-fortran            4.6.1           nompi_hacb5139_103    https://conda.anaconda.org/conda-forge
netcdf4                   1.6.5           nompi_py312h26027e0_100    https://conda.anaconda.org/conda-forge
nettle                    3.9.1                h7ab15ed_0    https://conda.anaconda.org/conda-forge
nlohmann_json             3.11.3               h59595ed_0    https://conda.anaconda.org/conda-forge
nodeenv                   1.8.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
nspr                      4.35                 h27087fc_0    https://conda.anaconda.org/conda-forge
nss                       3.100                hca3bf56_0    https://conda.anaconda.org/conda-forge
numpy                     1.26.4          py312heda63a1_0    https://conda.anaconda.org/conda-forge
ocl-icd                   2.3.2                hd590300_1    https://conda.anaconda.org/conda-forge
openh264                  2.4.1                h59595ed_0    https://conda.anaconda.org/conda-forge
openjpeg                  2.5.2                h488ebb8_0    https://conda.anaconda.org/conda-forge
openssl                   3.3.0                hd590300_0    https://conda.anaconda.org/conda-forge
p11-kit                   0.24.1               hc5aa10d_0    https://conda.anaconda.org/conda-forge
packaging                 24.0               pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pandas                    2.2.2           py312hfb8ada1_0    https://conda.anaconda.org/conda-forge
pango                     1.52.2               ha41ecd1_0    https://conda.anaconda.org/conda-forge
partd                     1.4.2              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pbr                       6.0.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pcre2                     10.43                hcad00b1_0    https://conda.anaconda.org/conda-forge
pillow                    10.3.0          py312hdcec9eb_0    https://conda.anaconda.org/conda-forge
pip                       24.0               pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pixman                    0.43.2               h59595ed_0    https://conda.anaconda.org/conda-forge
platformdirs              4.2.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pluggy                    1.5.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pooch                     1.8.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pre-commit                3.7.0              pyha770c72_0    https://conda.anaconda.org/conda-forge
proj                      9.3.1                h1d62c97_0    https://conda.anaconda.org/conda-forge
psutil                    5.9.8           py312h98912ed_0    https://conda.anaconda.org/conda-forge
pthread-stubs             0.4               h36c2ea0_1001    https://conda.anaconda.org/conda-forge
pugixml                   1.14                 h59595ed_0    https://conda.anaconda.org/conda-forge
pulseaudio-client         16.1                 hb77b528_5    https://conda.anaconda.org/conda-forge
pycparser                 2.22               pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pydata-sphinx-theme       0.15.2             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pygments                  2.18.0             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pykdtree                  1.3.12          py312hcc4bcb2_0    https://conda.anaconda.org/conda-forge
pyparsing                 3.1.2              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pyproj                    3.6.1           py312h38f1c37_5    https://conda.anaconda.org/conda-forge
pyshp                     2.3.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pysocks                   1.7.1              pyha2e5f31_6    https://conda.anaconda.org/conda-forge
pytest                    8.2.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pytest-cov                5.0.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pytest-xdist              3.5.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
python                    3.12.2          hab00c5b_0_cpython    https://conda.anaconda.org/conda-forge
python-dateutil           2.9.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
python-stratify           0.3.0           py312hc7c0aa3_1    https://conda.anaconda.org/conda-forge
python-tzdata             2024.1             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
python-xxhash             3.4.1           py312h98912ed_0    https://conda.anaconda.org/conda-forge
python_abi                3.12                    4_cp312    https://conda.anaconda.org/conda-forge
pytz                      2024.1             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pyvista                   0.43.7             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
pywavelets                1.4.1           py312hc7c0aa3_1    https://conda.anaconda.org/conda-forge
pyyaml                    6.0.1           py312h98912ed_1    https://conda.anaconda.org/conda-forge
qt-main                   5.15.8              h5810be5_19    https://conda.anaconda.org/conda-forge
readline                  8.2                  h8228510_1    https://conda.anaconda.org/conda-forge
requests                  2.31.0             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
scipy                     1.13.0          py312hc2bc53b_1    https://conda.anaconda.org/conda-forge
scitools-iris             3.10.0.dev31             pypi_0    pypi
scooby                    0.10.0             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
setuptools                69.5.1             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
setuptools-scm            8.1.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
shapely                   2.0.4           py312h9e6bd2c_0    https://conda.anaconda.org/conda-forge
six                       1.16.0             pyh6c4a22f_0    https://conda.anaconda.org/conda-forge
snappy                    1.2.0                hdb0a2a9_1    https://conda.anaconda.org/conda-forge
snowballstemmer           2.2.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
sortedcontainers          2.4.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
soupsieve                 2.5                pyhd8ed1ab_1    https://conda.anaconda.org/conda-forge
sphinx                    7.3.7              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
sphinx-copybutton         0.5.2              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
sphinx-design             0.5.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
sphinx-gallery            0.16.0             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
sphinxcontrib-apidoc      0.3.0                      py_1    https://conda.anaconda.org/conda-forge
sphinxcontrib-applehelp   1.0.8              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
sphinxcontrib-devhelp     1.0.6              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
sphinxcontrib-htmlhelp    2.0.5              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
sphinxcontrib-jsmath      1.0.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
sphinxcontrib-qthelp      1.0.7              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
sphinxcontrib-serializinghtml 1.1.10             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
sqlite                    3.45.3               h2c6b66d_0    https://conda.anaconda.org/conda-forge
svt-av1                   2.0.0                h59595ed_0    https://conda.anaconda.org/conda-forge
tbb                       2021.12.0            h00ab1b0_0    https://conda.anaconda.org/conda-forge
tbb-devel                 2021.12.0            h5ccd973_0    https://conda.anaconda.org/conda-forge
tblib                     3.0.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
tk                        8.6.13          noxft_h4845f30_101    https://conda.anaconda.org/conda-forge
toml                      0.10.2             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
toolz                     0.12.1             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
tornado                   6.4             py312h98912ed_0    https://conda.anaconda.org/conda-forge
typing-extensions         4.11.0               hd8ed1ab_0    https://conda.anaconda.org/conda-forge
typing_extensions         4.11.0             pyha770c72_0    https://conda.anaconda.org/conda-forge
tzdata                    2024a                h0c530f3_0    https://conda.anaconda.org/conda-forge
udunits2                  2.2.28               h40f5838_3    https://conda.anaconda.org/conda-forge
ukkonen                   1.0.1           py312h8572e83_4    https://conda.anaconda.org/conda-forge
urllib3                   2.2.1              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
utfcpp                    4.0.5                ha770c72_0    https://conda.anaconda.org/conda-forge
virtualenv                20.26.1            pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
vtk                       9.2.6           qt_py312h1234567_220    https://conda.anaconda.org/conda-forge
vtk-base                  9.2.6           qt_py312h1234567_220    https://conda.anaconda.org/conda-forge
vtk-io-ffmpeg             9.2.6           qt_py312h1234567_220    https://conda.anaconda.org/conda-forge
wheel                     0.43.0             pyhd8ed1ab_1    https://conda.anaconda.org/conda-forge
wslink                    2.0.2              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
x264                      1!164.3095           h166bdaf_2    https://conda.anaconda.org/conda-forge
x265                      3.5                  h924138e_3    https://conda.anaconda.org/conda-forge
xcb-util                  0.4.0                hd590300_1    https://conda.anaconda.org/conda-forge
xcb-util-image            0.4.0                h8ee46fc_1    https://conda.anaconda.org/conda-forge
xcb-util-keysyms          0.4.0                h8ee46fc_1    https://conda.anaconda.org/conda-forge
xcb-util-renderutil       0.3.9                hd590300_1    https://conda.anaconda.org/conda-forge
xcb-util-wm               0.4.1                h8ee46fc_1    https://conda.anaconda.org/conda-forge
xkeyboard-config          2.41                 hd590300_0    https://conda.anaconda.org/conda-forge
xorg-fixesproto           5.0               h7f98852_1002    https://conda.anaconda.org/conda-forge
xorg-kbproto              1.0.7             h7f98852_1002    https://conda.anaconda.org/conda-forge
xorg-libice               1.1.1                hd590300_0    https://conda.anaconda.org/conda-forge
xorg-libsm                1.2.4                h7391055_0    https://conda.anaconda.org/conda-forge
xorg-libx11               1.8.9                h8ee46fc_0    https://conda.anaconda.org/conda-forge
xorg-libxau               1.0.11               hd590300_0    https://conda.anaconda.org/conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    https://conda.anaconda.org/conda-forge
xorg-libxext              1.3.4                h0b41bf4_2    https://conda.anaconda.org/conda-forge
xorg-libxfixes            5.0.3             h7f98852_1004    https://conda.anaconda.org/conda-forge
xorg-libxrender           0.9.11               hd590300_0    https://conda.anaconda.org/conda-forge
xorg-libxt                1.3.0                hd590300_1    https://conda.anaconda.org/conda-forge
xorg-renderproto          0.11.1            h7f98852_1002    https://conda.anaconda.org/conda-forge
xorg-xextproto            7.3.0             h0b41bf4_1003    https://conda.anaconda.org/conda-forge
xorg-xf86vidmodeproto     2.3.1             h7f98852_1002    https://conda.anaconda.org/conda-forge
xorg-xproto               7.0.31            h7f98852_1007    https://conda.anaconda.org/conda-forge
xxhash                    0.8.2                hd590300_0    https://conda.anaconda.org/conda-forge
xz                        5.2.6                h166bdaf_0    https://conda.anaconda.org/conda-forge
yaml                      0.2.5                h7f98852_2    https://conda.anaconda.org/conda-forge
yarl                      1.9.4           py312h98912ed_0    https://conda.anaconda.org/conda-forge
zict                      3.0.0              pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
zipp                      3.17.0             pyhd8ed1ab_0    https://conda.anaconda.org/conda-forge
zlib                      1.2.13               hd590300_5    https://conda.anaconda.org/conda-forge
zstd                      1.5.6                ha6fb4c9_0    https://conda.anaconda.org/conda-forge

pip list

Package                       Version      Editable project location
----------------------------- ------------ --------------------------
accessible-pygments           0.0.4
aiohttp                       3.9.5
aiosignal                     1.3.1
alabaster                     0.7.16
antlr4-python3-runtime        4.11.1
asv_runner                    0.2.1
attrs                         23.2.0
Babel                         2.14.0
beautifulsoup4                4.12.3
Brotli                        1.1.0
Cartopy                       0.23.0
certifi                       2024.2.2
cf-units                      3.2.0
cffi                          1.16.0
cfgv                          3.3.1
cftime                        1.6.3
charset-normalizer            3.3.2
click                         8.1.7
click-default-group           1.2.4
cloudpickle                   3.0.0
cmocean                       4.0.3
colorama                      0.4.6
colorcet                      3.1.0
colorspacious                 1.1.2
contourpy                     1.2.1
coverage                      7.5.1
cycler                        0.12.1
Cython                        3.0.10
cytoolz                       0.12.3
dask                          2024.5.0
distlib                       0.3.8
distributed                   2024.5.0
docutils                      0.21.2
esmpy                         8.6.1
exceptiongroup                1.2.0
execnet                       2.1.1
filelock                      3.14.0
fonttools                     4.51.0
frozenlist                    1.4.1
fsspec                        2024.3.1
geovista                      0.4.1
identify                      2.5.36
idna                          3.7
ImageHash                     4.3.1
imagesize                     1.4.1
importlib_metadata            7.1.0
iniconfig                     2.0.0
iris-sample-data              2.4.0
Jinja2                        3.1.4
kiwisolver                    1.4.5
locket                        1.0.0
loguru                        0.7.2
MarkupSafe                    2.1.5
matplotlib                    3.8.4
mo-pack                       0.3.0
msgpack                       1.0.7
multidict                     6.0.5
munkres                       1.1.4
nc-time-axis                  1.4.1
netCDF4                       1.6.5
nodeenv                       1.8.0
numpy                         1.26.4
packaging                     24.0
pandas                        2.2.2
partd                         1.4.2
pbr                           6.0.0
pillow                        10.3.0
pip                           24.0
platformdirs                  4.2.1
pluggy                        1.5.0
pooch                         1.8.1
pre_commit                    3.7.0
psutil                        5.9.8
pycparser                     2.22
pydata-sphinx-theme           0.15.2
Pygments                      2.18.0
pykdtree                      1.3.12
pyparsing                     3.1.2
pyproj                        3.6.1
pyshp                         2.3.1
PySocks                       1.7.1
pytest                        8.2.0
pytest-cov                    5.0.0
pytest-xdist                  3.5.0
python-dateutil               2.9.0
pytz                          2024.1
pyvista                       0.43.7
PyWavelets                    1.4.1
PyYAML                        6.0.1
requests                      2.31.0
scipy                         1.13.0
scitools-iris                 3.10.0.dev31 /tmp/persistent/repos/iris
scooby                        0.10.0
setuptools                    69.5.1
setuptools-scm                8.1.0
shapely                       2.0.4
six                           1.16.0
snowballstemmer               2.2.0
sortedcontainers              2.4.0
soupsieve                     2.5
Sphinx                        7.3.7
sphinx-copybutton             0.5.2
sphinx_design                 0.5.0
sphinx-gallery                0.16.0
sphinxcontrib-apidoc          0.3.0
sphinxcontrib-applehelp       1.0.8
sphinxcontrib-devhelp         1.0.6
sphinxcontrib-htmlhelp        2.0.5
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.7
sphinxcontrib-serializinghtml 1.1.10
stratify                      0.3.0
tblib                         3.0.0
toml                          0.10.2
tomli                         2.0.1
toolz                         0.12.1
tornado                       6.4
typing_extensions             4.11.0
tzdata                        2024.1
ukkonen                       1.0.1
urllib3                       2.2.1
virtualenv                    20.26.1
vtk                           9.2.6
wheel                         0.43.0
wslink                        2.0.2
xxhash                        3.4.1
yarl                          1.9.4
zict                          3.0.0
zipp                          3.17.0

@rcomer
Copy link
Member

rcomer commented May 23, 2024

Erk. We added a test for the title adjustment at #2249 but it uses constrained layout: currently _draw_gridliner gets called within get_tightbbox and draw and (I think) both of those get called a couple of times when you save/show with constrained layout. With no layout engine, I guess draw gets called the once.

I guess an easy fix would be to just call _draw_gridliner within Gridliner.__init__ so it's always populated. Extra calls to _draw_gridliner are more efficient now than they were at 0.22. Perhaps there is a better way though.

In the meantime, a user workaround would be to force an extra draw with plt.gcf().draw_without_rendering().

@rcomer
Copy link
Member

rcomer commented May 24, 2024

I guess an easy fix would be to just call _draw_gridliner within Gridliner.__init__ so it's always populated.

Actually I think that would only help the very basic case and could go wrong if e.g. the extent changes between adding the GridLiner and drawing the figure (which does happen in the problem Iris test).

@trexfeathers
Copy link
Contributor Author

I guess an easy fix would be to just call _draw_gridliner within Gridliner.__init__ so it's always populated.

Actually I think that would only help the very basic case and could go wrong if e.g. the extent changes between adding the GridLiner and drawing the figure (which does happen in the problem Iris test).

Oh dang I was literally just writing a patch fix in Iris to do this!

@rcomer
Copy link
Member

rcomer commented May 24, 2024

I mean, I haven’t actually tried…

Though the simplest fix for Iris might be to just do this in the test

In the meantime, a user workaround would be to force an extra draw with plt.gcf().draw_without_rendering().

@trexfeathers
Copy link
Contributor Author

I mean, I haven’t actually tried…

Though the simplest fix for Iris might be to just do this in the test

In the meantime, a user workaround would be to force an extra draw with plt.gcf().draw_without_rendering().

Thus making the test pass but not actually saving the user from the problem when they are out in the real world 😉

The fix in __init__ produces this:

ValueError: Axes should be an instance of GeoAxes, got <class 'NoneType'>

But putting this at the top of iris.plot gets the whole test suite passing, unless you want to warn me off doing this:

class GeoAxesPatched(cartopy.mpl.geoaxes.GeoAxes):
    def _draw_preprocess(self, renderer):
        super()._draw_preprocess(renderer)

        for artist in self.artists:
            if hasattr(artist, "_draw_gridliner"):
                artist._draw_gridliner(renderer=renderer)


cartopy.mpl.geoaxes.GeoAxes = GeoAxesPatched

@rcomer
Copy link
Member

rcomer commented May 24, 2024

Fair enough. I was thinking of this as a purely Cartopy bug that Iris has no responsibility for. But in the quickplot context where Iris is automatically adding titles I guess Iris is arguably on the hook.

@trexfeathers
Copy link
Contributor Author

Fair enough. I was thinking of this as a purely Cartopy bug that Iris has no responsibility for. But in the quickplot context where Iris is automatically adding titles I guess Iris is arguably on the hook.

My apologies, I'm being very me-centric 🙉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants