8000 Pull request fixing the long standing issue #1317 · matplotlib/matplotlib@a9801b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit a9801b6

Browse files
paalgeanntzer
authored andcommitted
Pull request fixing the long standing issue #1317
Added doc string and raise of error for quadmesh Added test for RGB image in pcolorfast Added doc changes per efirings comments Doc change and use of pytest.raises Changed from TypeError to ValueError Removed whitespace Doc changes in response to comments Doc modified
1 parent 1a89250 commit a9801b6

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
@@ -6185,6 +6185,10 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
61856185
A 2D array or masked array. The values will be color-mapped.
61866186
This argument can only be passed positionally.
61876187
6188+
C can in some cases be 3D with the last dimension as rgb(a).
6189+
This is available when C qualifies for image or pcolorimage type,
6190+
will throw a TypeError if C is 3D and quadmesh.
6191+
61886192
X, Y : tuple or array-like, default: ``(0, N)``, ``(0, M)``
61896193
*X* and *Y* are used to specify the coordinates of the
61906194
quadrilaterals. There are different ways to do this:
@@ -6258,7 +6262,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
62586262
"'norm' must be an instance of 'mcolors.Normalize'")
62596263

62606264
C = args[-1]
6261-
nr, nc = np.shape(C)
6265+
nr, nc = np.shape(C)[:2]
62626266
if len(args) == 1:
62636267
style = "image"
62646268
x = [0, nc]
@@ -6279,6 +6283,10 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
62796283
else:
62806284
style = "pcolorimage"
62816285
elif x.ndim == 2 and y.ndim == 2:
6286+
if C.ndim > 2:
6287+
raise ValueError(
6288+
'pcolorfast needs to use quadmesh, '
6289+
'which is not supported when x and y are 2D and C 3D')
62826290
style = "quadmesh"
62836291
else:
62846292
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
@@ -5184,6 +5184,21 @@ def test_pcolorfast_colormapped(xy, cls):
51845184
assert type(ax.pcolorfast(*xy, data)) == cls
51855185

51865186

5187+
def test_pcolor_fast_RGB():
5188+
5189+
fig, ax = plt.subplots(1, 1)
5190+
5191+
np.random.seed(19680801)
5192+
C = np.random.rand(10, 10, 3) # RGB image [0,1]
5193+
x = np.arange(11, dtype=np.float)
5194+
y = np.arange(11, dtype=np.float)
5195+
5196+
xv, yv = np.meshgrid(x, y)
5197+
5198+
with pytest.raises(ValueError):
5199+
ax.pcolorfast(xv, yv, C)
5200+
5201+
51875202
def test_shared_scale():
51885203
fig, axs = plt.subplots(2, 2, sharex=True, sharey=True)
51895204

0 commit comments

Comments
 (0)
0