|
| 1 | +Add ``U``, ``V`` and ``C`` setter to ``Quiver`` |
| 2 | +----------------------------------------------- |
| 3 | + |
| 4 | +The ``U``, ``V`` and ``C`` values of the `~matplotlib.quiver.Quiver` |
| 5 | +can now be changed after the collection has been created. |
| 6 | + |
| 7 | +.. plot:: |
| 8 | + :include-source: true |
| 9 | + |
| 10 | + import matplotlib.pyplot as plt |
| 11 | + from matplotlib.quiver import Quiver |
| 12 | + import numpy as np |
| 13 | + |
| 14 | + fig, ax = plt.subplots() |
| 15 | + X = np.arange(-10, 10, 1) |
| 16 | + Y = np.arange(-10, 10, 1) |
| 17 | + U, V = np.meshgrid(X, Y) |
| 18 | + C = np.hypot(U, V) |
| 19 | + qc = ax.quiver(X, Y, U, V, C) |
| 20 | + |
| 21 | + qc.set_U(U/5) |
| 22 | + |
| 23 | + |
| 24 | +The number of arrows can also be changed. |
| 25 | + |
| 26 | +.. plot:: |
| 27 | + :include-source: true |
| 28 | + |
| 29 | + import matplotlib.pyplot as plt |
| 30 | + from matplotlib.quiver import Quiver |
| 31 | + import numpy as np |
| 32 | + |
| 33 | + fig, ax = plt.subplots() |
| 34 | + X = np.arange(-10, 10, 1) |
| 35 | + Y = np.arange(-10, 10, 1) |
| 36 | + U, V = np.meshgrid(X, Y) |
| 37 | + C = np.hypot(U, V) |
| 38 | + qc = ax.quiver(X, Y, U, V, C) |
| 39 | + |
| 40 | + # Get new X, Y, U, V, C |
| 41 | + X = np.arange(-10, 10, 2) |
| 42 | + Y = np.arange(-10, 10, 2) |
| 43 | + U, V = np.meshgrid(X, Y) |
| 44 | + C = np.hypot(U, V) |
| 45 | + X, Y = np.meshgrid(X, Y) |
| 46 | + XY = np.column_stack((X.ravel(), Y.ravel())) |
| 47 | + |
| 48 | + # Set new values |
| 49 | + qc.set_offsets(XY) |
| 50 | + qc.set_UVC(U, V, C) |
0 commit comments