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

Skip to content

Commit f57dc5a

Browse files
committed
MNT: Remove auto-flattening of input data to pcolormesh
If someone passes in a 2-D array, we should keep that in the array data
1 parent b080109 commit f57dc5a

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6216,9 +6216,6 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
62166216
X, Y, C, shading = self._pcolorargs('pcolormesh', *args,
62176217
shading=shading, kwargs=kwargs)
62186218
coords = np.stack([X, Y], axis=-1)
6219-
# convert to one dimensional array, except for 3D RGB(A) arrays
6220-
if C.ndim != 3:
6221-
C = C.ravel()
62226219

62236220
kwargs.setdefault('snap', mpl.rcParams['pcolormesh.snap'])
62246221

lib/matplotlib/tests/test_collections.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -904,13 +904,13 @@ def test_quadmesh_vmin_vmax():
904904
norm = mpl.colors.Normalize(vmin=0, vmax=1)
905905
coll = ax.pcolormesh([[1]], cmap=cmap, norm=norm)
906906
fig.canvas.draw()
907-
assert np.array_equal(coll.get_facecolors()[0, :], cmap(norm(1)))
907+
assert np.array_equal(coll.get_facecolors()[0, 0, :], cmap(norm(1)))
908908

909909
# Change the vmin/vmax of the norm so that the color is from
910910
# the bottom of the colormap now
911911
norm.vmin, norm.vmax = 1, 2
912912
fig.canvas.draw()
913-
assert np.array_equal(coll.get_facecolors()[0, :], cmap(norm(1)))
913+
assert np.array_equal(coll.get_facecolors()[0, 0, :], cmap(norm(1)))
914914

915915

916916
def test_quadmesh_alpha_array():
@@ -925,16 +925,16 @@ def test_quadmesh_alpha_array():
925925
coll2 = ax1.pcolormesh(x, y, z)
926926
coll2.set_alpha(alpha)
927927
plt.draw()
928-
assert_array_equal(coll1.get_facecolors()[:, -1], alpha_flat)
929-
assert_array_equal(coll2.get_facecolors()[:, -1], alpha_flat)
928+
assert_array_equal(coll1.get_facecolors()[..., -1], alpha)
929+
assert_array_equal(coll2.get_facecolors()[..., -1], alpha)
930930
# Or provide 1-D alpha:
931931
fig, (ax0, ax1) = plt.subplots(2)
932-
coll1 = ax0.pcolormesh(x, y, z, alpha=alpha_flat)
932+
coll1 = ax0.pcolormesh(x, y, z, alpha=alpha)
933933
coll2 = ax1.pcolormesh(x, y, z)
934-
coll2.set_alpha(alpha_flat)
934+
coll2.set_alpha(alpha)
935935
plt.draw()
936-
assert_array_equal(coll1.get_facecolors()[:, -1], alpha_flat)
937-
assert_array_equal(coll2.get_facecolors()[:, -1], alpha_flat)
936+
assert_array_equal(coll1.get_facecolors()[..., -1], alpha)
937+
assert_array_equal(coll2.get_facecolors()[..., -1], alpha)
938938

939939

940940
def test_alpha_validation():
@@ -982,7 +982,7 @@ def test_color_logic(pcfunc):
982982
pc.update_scalarmappable() # This is called in draw().
983983
# Define 2 reference "colors" here for multiple use.
984984
face_default = mcolors.to_rgba_array(pc._get_default_facecolor())
985-
mapped = pc.get_cmap()(pc.norm((z.ravel())))
985+
mapped = pc.get_cmap()(pc.norm((z.ravel() if pcfunc == plt.pcolor else z)))
986986
# GitHub issue #1302:
987987
assert mcolors.same_color(pc.get_edgecolor(), 'red')
988988
# Check setting attributes after initialization:
@@ -1001,30 +1001,30 @@ def test_color_logic(pcfunc):
10011001
# Reset edgecolor to default.
10021002
pc.set_edgecolor(None)
10031003
pc.update_scalarmappable()
1004-
assert mcolors.same_color(pc.get_edgecolor(), mapped)
1004+
assert np.array_equal(pc.get_edgecolor(), mapped)
10051005
pc.set_facecolor(None) # restore default for facecolor
10061006
pc.update_scalarmappable()
1007-
assert mcolors.same_color(pc.get_facecolor(), mapped)
1007+
assert np.array_equal(pc.get_facecolor(), mapped)
10081008
assert mcolors.same_color(pc.get_edgecolor(), 'none')
10091009
# Turn off colormapping entirely:
10101010
pc.set_array(None)
10111011
pc.update_scalarmappable()
10121012
assert mcolors.same_color(pc.get_edgecolor(), 'none')
10131013
assert mcolors.same_color(pc.get_facecolor(), face_default) # not mapped
10141014
# Turn it back on by restoring the array (must be 1D!):
1015-
pc.set_array(z.ravel())
1015+
pc.set_array(z.ravel() if pcfunc == plt.pcolor else z)
10161016
pc.update_scalarmappable()
1017-
assert mcolors.same_color(pc.get_facecolor(), mapped)
1017+
assert np.array_equal(pc.get_facecolor(), mapped)
10181018
assert mcolors.same_color(pc.get_edgecolor(), 'none')
10191019
# Give color via tuple rather than string.
10201020
pc = pcfunc(z, edgecolors=(1, 0, 0), facecolors=(0, 1, 0))
10211021
pc.update_scalarmappable()
1022-
assert mcolors.same_color(pc.get_facecolor(), mapped)
1022+
assert np.array_equal(pc.get_facecolor(), mapped)
10231023
assert mcolors.same_color(pc.get_edgecolor(), [[1, 0, 0, 1]])
10241024
# Provide an RGB array; mapping overrides it.
10251025
pc = pcfunc(z, edgecolors=(1, 0, 0), facecolors=np.ones((12, 3)))
10261026
pc.update_scalarmappable()
1027-
assert mcolors.same_color(pc.get_facecolor(), mapped)
1027+
assert np.array_equal(pc.get_facecolor(), mapped)
10281028
assert mcolors.same_color(pc.get_edgecolor(), [[1, 0, 0, 1]])
10291029
# Turn off the mapping.
10301030
pc.set_array(None)
@@ -1034,7 +1034,7 @@ def test_color_logic(pcfunc):
10341034
# And an RGBA array.
10351035
pc = pcfunc(z, edgecolors=(1, 0, 0), facecolors=np.ones((12, 4)))
10361036
pc.update_scalarmappable()
1037-
assert mcolors.same_color(pc.get_facecolor(), mapped)
1037+
assert np.array_equal(pc.get_facecolor(), mapped)
10381038
assert mcolors.same_color(pc.get_edgecolor(), [[1, 0, 0, 1]])
10391039
# Turn off the mapping.
10401040
pc.set_array(None)

0 commit comments

Comments
 (0)