You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'
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 errorAttributeError: 'NoneType' object has no attribute 'ndim'
. The.set_array(None)
works fine in my environment on a normalpcolormesh
, when I'm not using Cartopy.Code to reproduce
Traceback
Full environment definition
Operating system
Ubuntu 20.04
Cartopy version
0.21.1
pip list
The text was updated successfully, but these errors were encountered: