Skip to content

Backport PR #27754 on branch v3.8.x (fix quiver3d incorrect arrow colors) #27849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2727,15 +2727,10 @@ def calc_arrows(UVW):
UVW = np.column_stack(input_args[3:]).astype(float)

# Normalize rows of UVW
norm = np.linalg.norm(UVW, axis=1)

# If any row of UVW is all zeros, don't make a quiver for it
mask = norm > 0
XYZ = XYZ[mask]
if normalize:
UVW = UVW[mask] / norm[mask].reshape((-1, 1))
else:
UVW = UVW[mask]
norm = np.linalg.norm(UVW, axis=1)
norm[norm == 0] = 1
UVW = UVW / norm.reshape((-1, 1))

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

lines = [*shafts, *heads]
lines = [*shafts, *heads[::2], *heads[1::2]]
else:
lines = []

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 17 additions & 2 deletions lib/mpl_toolkits/mplot3d/tests/test_axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,8 @@ def test_mixedsamplesraises():
ax.plot_surface(X, Y, Z, cstride=50, rcount=10)


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


@mpl3d_image_comparison(['quiver3d_colorcoded.png'], style='mpl20')
def test_quiver3d_colorcoded():
fig = plt.figure()
ax = fig.add_subplot(projection='3d')

x = y = dx = dz = np.zeros(10)
z = dy = np.arange(10.)

color = plt.cm.Reds(dy/dy.max())
ax.quiver(x, y, z, dx, dy, dz, colors=color)
ax.set_ylim(0, 10)


def test_patch_modification():
fig = plt.figure()
ax = fig.add_subplot(projection="3d")
Expand Down Expand Up @@ -1519,7 +1533,8 @@ def test_minor_ticks():
ax.set_zticklabels(["half"], minor=True)


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