From 3ac646b7fbdeb7372a6ea14a9aeb7e996c1e0336 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 14 Oct 2025 00:24:57 +0200 Subject: [PATCH 1/4] add cmap parsing --- ultraplot/axes/plot.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ultraplot/axes/plot.py b/ultraplot/axes/plot.py index 49b0687c4..dc7ff4f27 100644 --- a/ultraplot/axes/plot.py +++ b/ultraplot/axes/plot.py @@ -1580,6 +1580,9 @@ def curved_quiver( density = _not_none(density, rc["curved_quiver.density"]) arrows_at_end = _not_none(arrow_at_end, rc["curved_quiver.arrows_at_end"]) + if cmap: + cmap = constructor.Colormap(cmap) + solver = CurvedQuiverSolver(x, y, density) if zorder is None: zorder = mlines.Line2D.zorder From e6f64fca5877d2b3e4efa939f4599b2f6c35214a Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 14 Oct 2025 00:41:35 +0200 Subject: [PATCH 2/4] add unittest --- ultraplot/tests/test_plot.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ultraplot/tests/test_plot.py b/ultraplot/tests/test_plot.py index e1662dd56..0092dbe20 100644 --- a/ultraplot/tests/test_plot.py +++ b/ultraplot/tests/test_plot.py @@ -587,3 +587,34 @@ def test_curved_quiver_multicolor_lines(): assert m.lines.get_array().size > 0 # we have colors set assert m.lines.get_cmap() is not None return fig + + +@pytest.mark.mpl_image_compare +@pytest.mark.parametrize( + "color_or_cmap", + ( + "k", # color + "viridis", # built-in + "viko", # bundled with ultraplot + ), +) +def test_curved_quiver_color_and_cmap(rng, cmap): + """ + Check that we can pass colors or colormaps + """ + x = np.linspace(0, 1, 5) + y = np.linspace(0, 1, 5) + X, Y = np.meshgrid(x, y) + U = np.ones_like(X) + V = np.ones_like(Y) + + # Deal with color or cmap + if cmap == "k": + cmap = None + color = "k" + else: + speed = rng.random(X.shape) + + fig, ax = uplt.subplots() + ax.curved_quiver(X, Y, U, V, color=speed, cmap=cmap) + return fig From bde73389924217bbdf12c7d760e71565974991fb Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 14 Oct 2025 00:42:15 +0200 Subject: [PATCH 3/4] correct input str --- ultraplot/tests/test_plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ultraplot/tests/test_plot.py b/ultraplot/tests/test_plot.py index 0092dbe20..f18707d69 100644 --- a/ultraplot/tests/test_plot.py +++ b/ultraplot/tests/test_plot.py @@ -591,7 +591,7 @@ def test_curved_quiver_multicolor_lines(): @pytest.mark.mpl_image_compare @pytest.mark.parametrize( - "color_or_cmap", + "cmap", ( "k", # color "viridis", # built-in From 394b97a7efb35f54a98ec8f703d0887fecbe5fbe Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 14 Oct 2025 00:49:36 +0200 Subject: [PATCH 4/4] more small typos --- ultraplot/tests/test_plot.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ultraplot/tests/test_plot.py b/ultraplot/tests/test_plot.py index f18707d69..e3eb9455d 100644 --- a/ultraplot/tests/test_plot.py +++ b/ultraplot/tests/test_plot.py @@ -609,12 +609,11 @@ def test_curved_quiver_color_and_cmap(rng, cmap): V = np.ones_like(Y) # Deal with color or cmap + color = rng.random(X.shape) if cmap == "k": cmap = None color = "k" - else: - speed = rng.random(X.shape) fig, ax = uplt.subplots() - ax.curved_quiver(X, Y, U, V, color=speed, cmap=cmap) + ax.curved_quiver(X, Y, U, V, color=color, cmap=cmap) return fig