Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94b0bca

Browse files
authored
Merge pull request #8690 from paalge/pcolorfast
Adds support for rgba and rgb images to pcolorfast
2 parents 7bd97de + a9801b6 commit 94b0bca

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Added support for RGB(A) images in pcolorfast
2+
`````````````````````````````````````````````
3+
4+
pcolorfast now accepts 3D images (RGB or RGBA) arrays if the X and Y
5+
specifications allow image or pcolorimage rendering; they remain unsupported by
6+
the more general quadmesh rendering

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6172,6 +6172,10 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
61726172
A 2D array or masked array. The values will be color-mapped.
61736173
This argument can only be passed positionally.
61746174
6175+
C can in some cases be 3D with the last dimension as rgb(a).
6176+
This is available when C qualifies for image or pcolorimage type,
6177+
will throw a TypeError if C is 3D and quadmesh.
6178+
61756179
X, Y : tuple or array-like, default: ``(0, N)``, ``(0, M)``
61766180
*X* and *Y* are used to specify the coordinates of the
61776181
quadrilaterals. There are different ways to do this:
@@ -6245,7 +6249,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
62456249
"'norm' must be an instance of 'mcolors.Normalize'")
62466250

62476251
C = args[-1]
6248-
nr, nc = np.shape(C)
6252+
nr, nc = np.shape(C)[:2]
62496253
if len(args) == 1:
62506254
style = "image"
62516255
x = [0, nc]
@@ -6266,6 +6270,10 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
62666270
else:
62676271
style = "pcolorimage"
62686272
elif x.ndim == 2 and y.ndim == 2:
6273+
if C.ndim > 2:
6274+
raise ValueError(
6275+
'pcolorfast needs to use quadmesh, '
6276+
'which is not supported when x and y are 2D and C 3D')
62696277
style = "quadmesh"
62706278
else:
62716279
raise TypeError("arguments do not match valid signatures")

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5190,6 +5190,21 @@ def test_pcolorfast_colormapped(xy, cls):
51905190
assert type(ax.pcolorfast(*xy, data)) == cls
51915191

51925192

5193+
def test_pcolor_fast_RGB():
5194+
5195+
fig, ax = plt.subplots(1, 1)
5196+
5197+
np.random.seed(19680801)
5198+
C = np.random.rand(10, 10, 3) # RGB image [0,1]
5199+
x = np.arange(11, dtype=np.float)
5200+
y = np.arange(11, dtype=np.float)
5201+
5202+
xv, yv = np.meshgrid(x, y)
5203+
5204+
with pytest.raises(ValueError):
5205+
ax.pcolorfast(xv, yv, C)
5206+
5207+
51935208
def test_shared_scale():
51945209
fig, axs = plt.subplots(2, 2, sharex=True, sharey=True)
51955210

0 commit comments

Comments
 (0)