From 993fe8c10ced84470ded045f563cd2c1e16412f8 Mon Sep 17 00:00:00 2001 From: MiniX16 Date: Sat, 17 May 2025 19:25:21 +0200 Subject: [PATCH] test: add 3D scatter test for cmap update --- lib/matplotlib/tests/test_collections.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index 27ce8b5d69bc..642e5829a7b5 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -492,6 +492,28 @@ def test_polycollection_close(): ax.set_ylim3d(0, 4) +@check_figures_equal(extensions=["png"]) +def test_scalarmap_change_cmap(fig_test, fig_ref): + # Ensure that changing the colormap of a 3D scatter after draw updates the colors. + + x, y, z = np.array(list(itertools.product( + np.arange(0, 5, 1), + np.arange(0, 5, 1), + np.arange(0, 5, 1) + ))).T + c = x + y + + # test + ax_test = fig_test.add_subplot(111, projection='3d') + sc_test = ax_test.scatter(x, y, z, c=c, s=40, cmap='jet') + fig_test.canvas.draw() + sc_test.set_cmap('viridis') + + # ref + ax_ref = fig_ref.add_subplot(111, projection='3d') + ax_ref.scatter(x, y, z, c=c, s=40, cmap='viridis') + + @image_comparison(['regularpolycollection_rotate.png'], remove_text=True) def test_regularpolycollection_rotate(): xx, yy = np.mgrid[:10, :10]