Skip to content

Commit cb8da22

Browse files
authored
Add Colormap parsing to curved-quiver (#369)
* add cmap parsing * add unittest * correct input str
1 parent 27c2883 commit cb8da22

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

ultraplot/axes/plot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,9 @@ def curved_quiver(
15801580
density = _not_none(density, rc["curved_quiver.density"])
15811581
arrows_at_end = _not_none(arrow_at_end, rc["curved_quiver.arrows_at_end"])
15821582

1583+
if cmap:
1584+
cmap = constructor.Colormap(cmap)
1585+
15831586
solver = CurvedQuiverSolver(x, y, density)
15841587
if zorder is None:
15851588
zorder = mlines.Line2D.zorder

ultraplot/tests/test_plot.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,3 +587,33 @@ def test_curved_quiver_multicolor_lines():
587587
assert m.lines.get_array().size > 0 # we have colors set
588588
assert m.lines.get_cmap() is not None
589589
return fig
590+
591+
592+
@pytest.mark.mpl_image_compare
593+
@pytest.mark.parametrize(
594+
"cmap",
595+
(
596+
"k", # color
597+
"viridis", # built-in
598+
"viko", # bundled with ultraplot
599+
),
600+
)
601+
def test_curved_quiver_color_and_cmap(rng, cmap):
602+
"""
603+
Check that we can pass colors or colormaps
604+
"""
605+
x = np.linspace(0, 1, 5)
606+
y = np.linspace(0, 1, 5)
607+
X, Y = np.meshgrid(x, y)
608+
U = np.ones_like(X)
609+
V = np.ones_like(Y)
610+
611+
# Deal with color or cmap
612+
color = rng.random(X.shape)
613+
if cmap == "k":
614+
cmap = None
615+
color = "k"
616+
617+
fig, ax = uplt.subplots()
618+
ax.curved_quiver(X, Y, U, V, color=color, cmap=cmap)
619+
return fig

0 commit comments

Comments
 (0)