Skip to content

Commit 6893bc8

Browse files
timhoffmdstansby
authored andcommitted
Backport PR #27754: fix quiver3d incorrect arrow colors
Update figure test image
1 parent e8d9bbd commit 6893bc8

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,15 +2727,10 @@ def calc_arrows(UVW):
27272727
UVW = np.column_stack(input_args[3:]).astype(float)
27282728

27292729
# Normalize rows of UVW
2730-
norm = np.linalg.norm(UVW, axis=1)
2731-
2732-
# If any row of UVW is all zeros, don't make a quiver for it
2733-
mask = norm > 0
2734-
XYZ = XYZ[mask]
27352730
if normalize:
2736-
UVW = UVW[mask] / norm[mask].reshape((-1, 1))
2737-
else:
2738-
UVW = UVW[mask]
2731+
norm = np.linalg.norm(UVW, axis=1)
2732+
norm[norm == 0] = 1
2733+
UVW = UVW / norm.reshape((-1, 1))
27392734

27402735
if len(XYZ) > 0:
27412736
# compute the shaft lines all at once with an outer product
@@ -2749,7 +2744,7 @@ def calc_arrows(UVW):
27492744
# transpose to get a list of lines
27502745
heads = heads.swapaxes(0, 1)
27512746

2752-
lines = [*shafts, *heads]
2747+
lines = [*shafts, *heads[::2], *heads[1::2]]
27532748
else:
27542749
lines = []
27552750

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@ def test_mixedsamplesraises():
806806
ax.plot_surface(X, Y, Z, cstride=50, rcount=10)
807807

808808

809-
@mpl3d_image_comparison(['quiver3d.png'], style='mpl20')
809+
# remove tolerance when regenerating the test image
810+
@mpl3d_image_comparison(['quiver3d.png'], style='mpl20', tol=0.003)
810811
def test_quiver3d():
811812
fig = plt.figure()
812813
ax = fig.add_subplot(projection='3d')
@@ -853,6 +854,19 @@ def test_quiver3d_masked():
853854
ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True)
854855

855856

857+
@mpl3d_image_comparison(['quiver3d_colorcoded.png'], style='mpl20')
858+
def test_quiver3d_colorcoded():
859+
fig = plt.figure()
860+
ax = fig.add_subplot(projection='3d')
861+
862+
x = y = dx = dz = np.zeros(10)
863+
z = dy = np.arange(10.)
864+
865+
color = plt.cm.Reds(dy/dy.max())
866+
ax.quiver(x, y, z, dx, dy, dz, colors=color)
867+
ax.set_ylim(0, 10)
868+
869+
856870
def test_patch_modification():
857871
fig = plt.figure()
858872
ax = fig.add_subplot(projection="3d")
@@ -1519,7 +1533,8 @@ def test_minor_ticks():
15191533
ax.set_zticklabels(["half"], minor=True)
15201534

15211535

1522-
@mpl3d_image_comparison(['errorbar3d_errorevery.png'], style='mpl20')
1536+
# remove tolerance when regenerating the test image
1537+
@mpl3d_image_comparison(['errorbar3d_errorevery.png'], style='mpl20', tol=0.003)
15231538
def test_errorbar3d_errorevery():
15241539
"""Tests errorevery functionality for 3D errorbars."""
15251540
t = np.arange(0, 2*np.pi+.1, 0.01)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy