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

Skip to content

Commit d4f3ec3

Browse files
committed
scatter3d: Test sorting of face/edge colours.
1 parent 5bd536b commit d4f3ec3

1 file changed

Lines changed: 36 additions & 18 deletions

File tree

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import functools
2+
import itertools
23

34
import pytest
45

@@ -254,27 +255,44 @@ def test_scatter3d_depthshade_false():
254255

255256

256257
@check_figures_equal(extensions=['png'])
257-
def test_scatter3d_size(fig_ref, fig_test):
258-
"""Test that large markers in correct position (issue #18135)"""
259-
x = np.arange(10)
260-
x, y = np.meshgrid(x, x)
261-
z = np.arange(100).reshape(10, 10)
262-
263-
s = np.full(z.shape, 5)
264-
s[0, 0] = 100
265-
s[-1, 0] = 100
266-
s[0, -1] = 100
267-
s[-1, -1] = 100
258+
def test_scatter3d_sorting(fig_ref, fig_test):
259+
"""Test that marker properties are correctly sorted."""
268260

269-
ax_ref = fig_ref.gca(projection='3d')
270-
ax_test = fig_test.gca(projection='3d')
261+
y, x = np.mgrid[:10, :10]
262+
z = np.arange(x.size).reshape(x.shape)
263+
264+
sizes = np.full(z.shape, 25)
265+
sizes[0::2, 0::2] = 100
266+
sizes[1::2, 1::2] = 100
267+
268+
facecolors = np.full(z.shape, 'C0')
269+
facecolors[:5, :5] = 'C1'
270+
facecolors[6:, :4] = 'C2'
271+
facecolors[6:, 6:] = 'C3'
271272

272-
small = np.ma.masked_array(z, s == 100, dtype=float)
273-
large = np.ma.masked_array(z, s != 100, dtype=float)
273+
edgecolors = np.full(z.shape, 'C4')
274+
edgecolors[1:5, 1:5] = 'C5'
275+
edgecolors[5:9, 1:5] = 'C6'
276+
edgecolors[5:9, 5:9] = 'C7'
274277

275-
ax_ref.scatter(x, y, large, s=100, c="C0", alpha=1)
276-
ax_ref.scatter(x, y, small, s=5, c="C0", alpha=1)
277-
ax_test.scatter(x, y, z, s=s, c="C0", alpha=1)
278+
x, y, z, sizes, facecolors, edgecolors = [
279+
a.flatten()
280+
for a in [x, y, z, sizes, facecolors, edgecolors]
281+
]
282+
283+
ax_ref = fig_ref.gca(projection='3d')
284+
sets = (np.unique(a) for a in [sizes, facecolors, edgecolors])
285+
for s, fc, ec in itertools.product(*sets):
286+
subset = (
287+
(sizes != s) |
288+
(facecolors != fc) |
289+
(edgecolors != ec)
290+
)
291+
subset = np.ma.masked_array(z, subset, dtype=float)
292+
ax_ref.scatter(x, y, subset, s=s, fc=fc, ec=ec, alpha=1)
293+
294+
ax_test = fig_test.gca(projection='3d')
295+
ax_test.scatter(x, y, z, s=sizes, fc=facecolors, ec=edgecolors, alpha=1)
278296

279297

280298
@pytest.mark.parametrize('azim', [-50, 130]) # yellow first, blue first

0 commit comments

Comments
 (0)