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

pcolormesh.set_array(None) not longer works? #2171

Closed
julietbravo opened this issue Apr 24, 2023 · 2 comments · Fixed by #2166
Closed

pcolormesh.set_array(None) not longer works? #2171

julietbravo opened this issue Apr 24, 2023 · 2 comments · Fixed by #2166
Milestone

Comments

@julietbravo
Copy link

Description

The code from this question: https://stackoverflow.com/questions/48566732/plot-rgb-using-cartopy-pcolormesh (but also my minimal example below) no longer works. More specifically, the line pcol.set_array(None) gives an error AttributeError: 'NoneType' object has no attribute 'ndim'. The .set_array(None) works fine in my environment on a normal pcolormesh, when I'm not using Cartopy.

Code to reproduce

import numpy as np
import matplotlib.pyplot as pl
import cartopy
import cartopy.crs as ccrs

bbox = [3.5, 6.5, 51.45, 52.65]
lon = np.linspace(3.5, 6.5, 100)
lat = np.linspace(51.45, 52.65, 100)

r, g = np.meshgrid(np.linspace(0,255,100),np.linspace(0,255,100))
b=255-r

rgb = np.array([r,g,b]).T
color_tuple = rgb.transpose((1,0,2)).reshape((rgb.shape[0]*rgb.shape[1],rgb.shape[2]))/255.0

proj = ccrs.LambertConformal(central_longitude=4.9, central_latitude=51.967)

pl.figure()
ax = pl.subplot(111, projection=proj)
ax.set_extent(bbox, ccrs.PlateCarree())

m = pl.pcolormesh(lon, lat, r, color=color_tuple, linewidth=0, transform=ccrs.PlateCarree())
m.set_array(None)

Traceback

In [13]: run pcolor_cartopy.py
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/tmp/pcolor_cartopy.py:38
     35 ax.set_extent(bbox, ccrs.PlateCarree())
     37 m = pl.pcolormesh(lon, lat, r, color=color_tuple, linewidth=0, transform=ccrs.PlateCarree())
---> 38 m.set_array(None)

File ~/.local/lib/python3.8/site-packages/cartopy/mpl/geocollection.py:29, in GeoQuadMesh.set_array(self, A)
     27 def set_array(self, A):
     28     # raise right away if A is 2-dimensional.
---> 29     if A.ndim > 1:
     30         raise ValueError('Collections can only map rank 1 arrays. '
     31                          'You likely want to call with a flattened array '
     32                          'using collection.set_array(A.ravel()) instead.')
     34     # Only use the mask attribute if it is there.

AttributeError: 'NoneType' object has no attribute 'ndim'
Full environment definition

Operating system

Ubuntu 20.04

Cartopy version

0.21.1

pip list

bart@eddy:~/tmp$ pip list
Package                 Version
----------------------- --------------
affine                  2.4.0
apturl                  0.5.2
asttokens               2.2.1
attrs                   22.2.0
backcall                0.2.0
bcrypt                  3.1.7
blinker                 1.4
Brlapi                  0.7.0
Brotli                  1.0.7
Cartopy                 0.21.1
certifi                 2019.11.28
cftime                  1.6.2
chardet                 3.0.4
chrome-gnome-shell      0.0.0
Click                   7.0
click-plugins           1.1.1
cligj                   0.7.2
cloudpickle             2.2.1
colorama                0.4.3
command-not-found       0.3
contourpy               1.0.7
cryptography            2.8
cupshelpers             1.0
cycler                  0.11.0
dask                    2023.3.0
dbus-python             1.2.16
decorator               5.1.1
defer                   1.0.6
distro                  1.4.0
distro-info             0.23ubuntu1
dnspython               1.16.0
entrypoints             0.3
executing               1.2.0
fonttools               4.38.0
fsspec                  2023.3.0
GDAL                    3.0.4
gpg                     1.13.1-unknown
greenlet                0.4.15
gssapi                  1.6.1
httplib2                0.14.0
idna                    2.8
ifaddr                  0.1.6
importlib-metadata      6.0.0
importlib-resources     5.12.0
ipython                 8.10.0
jedi                    0.18.2
keyring                 18.0.1
kiwisolver              1.4.4
language-selector       0.1
launchpadlib            1.10.13
lazr.restfulclient      0.14.2
lazr.uri                1.0.3
llvmlite                0.39.1
locket                  1.0.0
louis                   3.12.0
lz4                     3.0.2+dfsg
macaroonbakery          1.3.1
Markdown                3.1.1
matplotlib              3.7.0
matplotlib-inline       0.1.6
meld                    3.20.2
msgpack                 0.6.2
netCDF4                 1.6.2
netifaces               0.10.4
nose                    1.3.7
numba                   0.56.4
numpy                   1.23.5
oauthlib                3.1.0
olefile                 0.46
packaging               23.0
pandas                  1.5.3
paramiko                2.6.0
parso                   0.8.3
partd                   1.3.0
pexpect                 4.6.0
pickleshare             0.7.5
Pillow                  7.0.0
pip                     23.0.1
progress                1.6
prompt-toolkit          3.0.37
protobuf                3.6.1
pure-eval               0.2.2
py-cpuinfo              5.0.0
py3dns                  3.2.1
pycairo                 1.16.2
pycrypto                2.6.1
pycups                  1.9.73
Pygments                2.14.0
PyGObject               3.36.0
PyJWT                   1.7.1
pykerberos              1.1.14
pymacaroons             0.13.0
PyNaCl                  1.3.0
pynvim                  0.4.1
PyOpenGL                3.1.0
pyparsing               3.0.9
pyproj                  3.4.1
PyQt5                   5.15.9
PyQt5-Qt5               5.15.2
PyQt5-sip               12.11.1
PyQt6                   6.4.2
PyQt6-Qt6               6.4.2
PyQt6-sip               13.4.1
pyRFC3339               1.1
pyshp                   2.3.1
python-apt              2.0.1
python-dateutil         2.8.2
python-debian           0.1.36ubuntu1
python-lzo              1.12
pytz                    2022.7.1
pyxdg                   0.26
PyYAML                  5.3.1
rasterio                1.3.6
rencode                 1.0.6
reportlab               3.5.34
requests                2.22.0
requests-unixsocket     0.2.0
rioxarray               0.13.4
scipy                   1.10.1
screen-resolution-extra 0.0.0
SecretStorage           2.3.1
setproctitle            1.1.10
setuptools              45.2.0
shapely                 2.0.1
simplejson              3.16.0
six                     1.16.0
snuggs                  1.4.7
ssh-import-id           5.10
stack-data              0.6.2
systemd-python          234
toolz                   0.12.0
traitlets               5.9.0
ubuntu-advantage-tools  8001
ubuntu-drivers-common   0.0.0
ufw                     0.36
unattended-upgrades     0.1
uritools                3.0.0
urllib3                 1.25.8
wadllib                 1.3.3
wcwidth                 0.2.6
wheel                   0.34.2
xarray                  2023.1.0
xkit                    0.0.0
xpra                    3.0.6
zeroconf                0.24.4
zipp                    3.15.0

@rcomer
Copy link
Member

rcomer commented Apr 24, 2023

This has also been requested at #2045. I guess it stopped working at 0.19, as that was when the GeoQuadMesh was introduced. #1496.

@julietbravo
Copy link
Author

Sorry, missed that!

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

Successfully merging a pull request may close this issue.

3 participants