|
13 | 13 | import matplotlib.collections as mcollections
|
14 | 14 | import matplotlib.colors as mcolors
|
15 | 15 | import matplotlib.path as mpath
|
| 16 | +import matplotlib.quiver as mquiver |
16 | 17 | import matplotlib.transforms as mtransforms
|
17 | 18 | from matplotlib.collections import (Collection, LineCollection,
|
18 | 19 | EventCollection, PolyCollection)
|
@@ -347,6 +348,56 @@ def test_collection_log_datalim(fig_test, fig_ref):
|
347 | 348 | ax_ref.plot(x, y, marker="o", ls="")
|
348 | 349 |
|
349 | 350 |
|
| 351 | +def test_quiver_offsets(): |
| 352 | + fig, ax = plt.subplots() |
| 353 | + x = np.arange(-10, 10, 1) |
| 354 | + y = np.arange(-10, 10, 1) |
| 355 | + U, V = np.meshgrid(x, y) |
| 356 | + X = U.ravel() |
| 357 | + Y = V.ravel() |
| 358 | + qc = mquiver.Quiver(ax, X, Y, U, V) |
| 359 | + ax.add_collection(qc) |
| 360 | + ax.autoscale_view() |
| 361 | + |
| 362 | + expected_offsets = np.column_stack([X, Y]) |
| 363 | + np.testing.assert_allclose(expected_offsets, qc.get_offsets()) |
| 364 | + |
| 365 | + new_offsets = np.column_stack([(X + 10).ravel(), Y.ravel()]) |
| 366 | + qc.set_offsets(new_offsets) |
| 367 | + |
| 368 | + np.testing.assert_allclose(qc.get_offsets(), new_offsets) |
| 369 | + |
| 370 | + |
| 371 | +def test_quiver_UVC(): |
| 372 | + fig, ax = plt.subplots() |
| 373 | + X = np.arange(-10, 10, 1) |
| 374 | + Y = np.arange(-10, 10, 1) |
| 375 | + U, V = np.meshgrid(X, Y) |
| 376 | + M = np.hypot(U, V) |
| 377 | + qc = mquiver.Quiver( |
| 378 | + ax, X, Y, U, V, M |
| 379 | + ) |
| 380 | + ax.add_collection(qc) |
| 381 | + ax.autoscale_view() |
| 382 | + |
| 383 | + np.testing.assert_allclose(qc.U, U.ravel()) |
| 384 | + np.testing.assert_allclose(qc.V, V.ravel()) |
| 385 | + np.testing.assert_allclose(qc.get_array(), M.ravel()) |
| 386 | + |
| 387 | + qc.set_UVC(U/2, V/3) |
| 388 | + np.testing.assert_allclose(qc.U, U.ravel() / 2) |
| 389 | + np.testing.assert_allclose(qc.V, V.ravel() / 3) |
| 390 | + |
| 391 | + qc.set_U(U/4) |
| 392 | + np.testing.assert_allclose(qc.U, U.ravel() / 4) |
| 393 | + |
| 394 | + qc.set_V(V/6) |
| 395 | + np.testing.assert_allclose(qc.V, V.ravel() / 6) |
| 396 | + |
| 397 | + qc.set_C(M/10) |
| 398 | + np.testing.assert_allclose(qc.get_array(), M.ravel() / 10) |
| 399 | + |
| 400 | + |
350 | 401 | def test_quiver_limits():
|
351 | 402 | ax = plt.axes()
|
352 | 403 | x, y = np.arange(8), np.arange(10)
|
|
0 commit comments