8000 Merge pull request #16614 from anntzer/q3d · matplotlib/matplotlib@0cbbf1f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0cbbf1f

Browse files
authored
Merge pull request #16614 from anntzer/q3d
Cleanup quiver3d examples.
2 parents 70d59ae + ced2f7f commit 0cbbf1f

File tree

2 files changed

+12
-53
lines changed

2 files changed

+12
-53
lines changed
Binary file not shown.

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -371,33 +371,23 @@ def test_mixedsamplesraises():
371371
ax.plot_surface(X, Y, Z, cstride=50, rcount=10)
372372

373373

374-
@mpl3d_image_comparison(['quiver3d.png'])
374+
@mpl3d_image_comparison(
375+
['quiver3d.png', 'quiver3d_pivot_middle.png', 'quiver3d_pivot_tail.png'])
375376
def test_quiver3d():
376-
fig = plt.figure()
377-
ax = fig.gca(projection='3d')
378-
379377
x, y, z = np.ogrid[-1:0.8:10j, -1:0.8:10j, -1:0.6:3j]
380-
381378
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
382379
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
383-
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
384-
np.sin(np.pi * z))
380+
w = (2/3)**0.5 * np.cos(np.pi * x) * np.cos(np.pi * y) * np.sin(np.pi * z)
381+
for pivot in ['tip', 'middle', 'tail']:
382+
ax = plt.figure().add_subplot(projection='3d')
383+
ax.quiver(x, y, z, u, v, w, length=0.1, pivot=pivot, normalize=True)
385384

386-
ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True)
387-
388-
389-
@mpl3d_image_comparison(['quiver3d_empty.png'])
390-
def test_quiver3d_empty():
391-
fig = plt.figure()
392-
ax = fig.gca(projection='3d')
393-
394-
x, y, z = np.ogrid[-1:0.8:0j, -1:0.8:0j, -1:0.6:0j]
395-
396-
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
397-
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
398-
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
399-
np.sin(np.pi * z))
400385

386+
@check_figures_equal(extensions=["png"])
387+
def test_quiver3d_empty(fig_test, fig_ref):
388+
fig_ref.add_subplot(projection='3d')
389+
x = y = z = u = v = w = []
390+
ax = fig_test.add_subplot(projection='3d')
401391
ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True)
402392

403393

@@ -412,44 +402,13 @@ def test_quiver3d_masked():
412402

413403
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
414404
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
415-
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
416-
np.sin(np.pi * z))
405+
w = (2/3)**0.5 * np.cos(np.pi * x) * np.cos(np.pi * y) * np.sin(np.pi * z)
417406
u = np.ma.masked_where((-0.4 < x) & (x < 0.1), u, copy=False)
418407
v = np.ma.masked_where((0.1 < y) & (y < 0.7), v, copy=False)
419408

420409
ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True)
421410

422411

423-
@mpl3d_image_comparison(['quiver3d_pivot_middle.png'])
424-
def test_quiver3d_pivot_middle():
425-
fig = plt.figure()
426-
ax = fig.gca(projection='3d')
427-
428-
x, y, z = np.ogrid[-1:0.8:10j, -1:0.8:10j, -1:0.6:3j]
429-
430-
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
431-
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
432-
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
433-
np.sin(np.pi * z))
434-
435-
ax.quiver(x, y, z, u, v, w, length=0.1, pivot='middle', normalize=True)
436-
437-
438-
@mpl3d_image_comparison(['quiver3d_pivot_tail.png'])
439-
def test_quiver3d_pivot_tail():
440-
fig = plt.figure()
441-
ax = fig.gca(projection='3d')
442-
443-
x, y, z = np.ogrid[-1:0.8:10j, -1:0.8:10j, -1:0.6:3j]
444-
445-
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
446-
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
447-
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
448-
np.sin(np.pi * z))
449-
450-
ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tail', normalize=True)
451-
452-
453412
@mpl3d_image_comparison(['poly3dcollection_closed.png'])
454413
def test_poly3dcollection_closed():
455414
fig = plt.figure()

0 commit comments

Comments
 (0)
0