Skip to content

Backport PR #8690 on branch v3.1.x #13709

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/api/api_changes/2019-02-11-PGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Added support for RGB(A) images in pcolorfast
`````````````````````````````````````````````

pcolorfast now accepts 3D images (RGB or RGBA) arrays if the X and Y
specifications allow image or pcolorimage rendering; they remain unsupported by
the more general quadmesh rendering
10 changes: 9 additions & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6185,6 +6185,10 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
A 2D array or masked array. The values will be color-mapped.
This argument can only be passed positionally.

C can in some cases be 3D with the last dimension as rgb(a).
This is available when C qualifies for image or pcolorimage type,
will throw a TypeError if C is 3D and quadmesh.

X, Y : tuple or array-like, default: ``(0, N)``, ``(0, M)``
*X* and *Y* are used to specify the coordinates of the
quadrilaterals. There are different ways to do this:
Expand Down Expand Up @@ -6258,7 +6262,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
"'norm' must be an instance of 'mcolors.Normalize'")

C = args[-1]
nr, nc = C.shape
nr, nc = np.shape(C)[:2]
if len(args) == 1:
style = "image"
x = [0, nc]
Expand All @@ -6279,6 +6283,10 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
else:
style = "pcolorimage"
elif x.ndim == 2 and y.ndim == 2:
if C.ndim > 2:
raise ValueError(
'pcolorfast needs to use quadmesh, '
'which is not supported when x and y are 2D and C 3D')
style = "quadmesh"
else:
raise TypeError("arguments do not match valid signatures")
Expand Down
15 changes: 15 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5190,6 +5190,21 @@ def test_pcolorfast_colormapped(xy, cls):
assert type(ax.pcolorfast(*xy, data)) == cls


def test_pcolor_fast_RGB():

fig, ax = plt.subplots(1, 1)

np.random.seed(19680801)
C = np.random.rand(10, 10, 3) # RGB image [0,1]
x = np.arange(11, dtype=np.float)
y = np.arange(11, dtype=np.float)

xv, yv = np.meshgrid(x, y)

with pytest.raises(ValueError):
ax.pcolorfast(xv, yv, C)


def test_shared_scale():
fig, axs = plt.subplots(2, 2, sharex=True, sharey=True)

Expand Down