I have asked similar question about plotting RGB array on normal axis. The idea is plotting one channel of RGB array and set the facecolor by the combination of RGB.
I wanna apply this method to axis with projection.
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
np.random.seed(100)
x = np.arange(10, 20)
y = np.arange(0, 10)
x, y = np.meshgrid(x, y)
img = np.random.randint(low=0, high=255, size=(10, 10, 3))
ax = plt.axes(projection=ccrs.PlateCarree())
mesh = ax.pcolormesh(x, y, img[:, :,0], facecolors=img.reshape(-1, 3)/255)
mesh.set_array(None)
plt.show()
However, I got this error because of None type.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[59], line 17
14 ax = plt.axes(projection=ccrs.PlateCarree())
16 mesh = ax.pcolormesh(x, y, img[:, :,0], facecolors=img.reshape(-1, 3)/255)
---> 17 mesh.set_array(None)
18 plt.show()
File ~/miniconda3/envs/enpt/lib/python3.10/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'