From 414b1b738b1813c962e2de0412684737d31c8a7e Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 21 Jan 2017 22:07:01 +0000 Subject: [PATCH 01/11] Make quiver docstring numpydoc --- lib/matplotlib/quiver.py | 93 ++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 51 deletions(-) diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index 83a3a26019c8..e994e531b1c8 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -45,18 +45,6 @@ quiver(X, Y, U, V, **kw) quiver(X, Y, U, V, C, **kw) -Arguments: - - *X*, *Y*: - The x and y coordinates of the arrow locations (default is tail of - arrow; see *pivot* kwarg) - - *U*, *V*: - Give the x and y components of the arrow vectors - - *C*: - An optional array used to map colors to the arrows - All arguments may be 1-D or 2-D arrays or sequences. If *X* and *Y* are absent, they will be generated as a uniform grid. If *U* and *V* are 2-D arrays but *X* and *Y* are 1-D, and if ``len(X)`` and ``len(Y)`` @@ -66,17 +54,37 @@ *U*, *V*, *C* may be masked arrays, but masked *X*, *Y* are not supported at present. -Keyword arguments: +The defaults give a slightly swept-back arrow; to make the head a +triangle, make *headaxislength* the same as *headlength*. To make the +arrow more pointed, reduce *headwidth* or increase *headlength* and +*headaxislength*. To make the head smaller relative to the shaft, +scale down all the head parameters. You will probably do best to leave +minshaft alone. - *units*: [ 'width' | 'height' | 'dots' | 'inches' | 'x' | 'y' | 'xy' ] +linewidths and edgecolors can be used to customize the arrow +outlines. + +Parameters +---------- +X : array, optional + The x coordinates of the arrow locations +Y : array, optional + The y coordinates of the arrow locations +U : array + The x components of the arrow vectors +V : array + The y components of the arrow vectors +C : array, optional + The arrow colors +units : [ 'width' | 'height' | 'dots' | 'inches' | 'x' | 'y' | 'xy' ] Arrow units; the arrow dimensions *except for length* are in - multiples of this unit. + multiples of this unit - * 'width' or 'height': the width or height of the axes + *width* or *height*: the width or height of the axis - * 'dots' or 'inches': pixels or inches, based on the figure dpi + *dots* or *inches*: pixels or inches, based on the figure dpi - * 'x', 'y', or 'xy': *X*, *Y*, or sqrt(X^2+Y^2) data units + *x*, *y*, or *xy*: *X*, *Y*, or sqrt(X^2+Y^2) data units The arrows scale differently depending on the units. For 'x' or 'y', the arrows get larger as one zooms in; for other @@ -84,10 +92,8 @@ 'width or 'height', the arrow size increases with the width and height of the axes, respectively, when the window is resized; for 'dots' or 'inches', resizing does not change the arrows. - - - *angles*: [ 'uv' | 'xy' | array ] - With the default 'uv', the arrow axis aspect ratio is 1, so that +angles : [ 'uv' | 'xy' ], array, optional + With the default *uv*, the arrow axis aspect ratio is 1, so that if *U*==*V* the orientation of the arrow on the plot is 45 degrees CCW from the horizontal axis (positive to the right). With 'xy', the arrow points from (x,y) to (x+u, y+v). @@ -96,15 +102,13 @@ of values in degrees, CCW from the horizontal axis. Note: inverting a data axis will correspondingly invert the arrows *only* with `angles='xy'`. - - *scale*: [ *None* | float ] +scale : None, float, optional Data units per arrow length unit, e.g., m/s per plot width; a smaller scale parameter makes the arrow longer. If *None*, a simple autoscaling algorithm is used, based on the average vector length and the number of vectors. The arrow length unit is given by the *scale_units* parameter - - *scale_units*: *None*, or any of the *units* options. +scale_units : [ 'width' | 'height' | 'dots' | 'inches' | 'x' | 'y' | 'xy' ], None, optional For example, if *scale_units* is 'inches', *scale* is 2.0, and ``(u,v) = (1,0)``, then the vector will be 0.5 inches long. If *scale_units* is 'width', then the vector will be half the width @@ -114,52 +118,39 @@ units. To plot vectors in the x-y plane, with u and v having the same units as x and y, use "angles='xy', scale_units='xy', scale=1". - - *width*: +width : optional Shaft width in arrow units; default depends on choice of units, above, and number of vectors; a typical starting value is about 0.005 times the width of the plot. - - *headwidth*: scalar +headwidth : scalar, optional Head width as multiple of shaft width, default is 3 - - *headlength*: scalar +headlength : scalar, optional Head length as multiple of shaft width, default is 5 - - *headaxislength*: scalar +headaxislength : scalar, optional Head length at shaft intersection, default is 4.5 - - *minshaft*: scalar +minshaft : scalar, optional Length below which arrow scales, in units of head length. Do not set this to less than 1, or small arrows will look terrible! Default is 1 - - *minlength*: scalar +minlength : scalar, optional Minimum length as a multiple of shaft width; if an arrow length is less than this, plot a dot (hexagon) of this diameter instead. Default is 1. - - *pivot*: [ 'tail' | 'mid' | 'middle' | 'tip' ] +pivot : [ 'tail' | 'mid' | 'middle' | 'tip' ], optional The part of the arrow that is at the grid point; the arrow rotates about this point, hence the name *pivot*. - - *color*: [ color | color sequence ] +color : [ color | color sequence ], optional This is a synonym for the :class:`~matplotlib.collections.PolyCollection` facecolor kwarg. If *C* has been set, *color* has no effect. -The defaults give a slightly swept-back arrow; to make the head a -triangle, make *headaxislength* the same as *headlength*. To make the -arrow more pointed, reduce *headwidth* or increase *headlength* and -*headaxislength*. To make the head smaller relative to the shaft, -scale down all the head parameters. You will probably do best to leave -minshaft alone. - -linewidths and edgecolors can be used to customize the arrow -outlines. Additional :class:`~matplotlib.collections.PolyCollection` +Notes +----- +Additional :class:`~matplotlib.collections.PolyCollection` keyword arguments: %(PolyCollection)s + """ % docstring.interpd.params _quiverkey_doc = """ From b8e0f820e68d520da6ed520622cd62a08cbc9089 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 21 Jan 2017 22:56:59 +0000 Subject: [PATCH 02/11] Clean up quiverkey doc string --- lib/matplotlib/quiver.py | 85 ++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index e994e531b1c8..085ac94f4583 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -38,21 +38,24 @@ _quiver_doc = """ Plot a 2-D field of arrows. -call signatures:: +Call signatures:: quiver(U, V, **kw) quiver(U, V, C, **kw) quiver(X, Y, U, V, **kw) quiver(X, Y, U, V, C, **kw) -All arguments may be 1-D or 2-D arrays or sequences. If *X* and *Y* -are absent, they will be generated as a uniform grid. If *U* and *V* -are 2-D arrays but *X* and *Y* are 1-D, and if ``len(X)`` and ``len(Y)`` -match the column and row dimensions of *U*, then *X* and *Y* will be +*U* and *V* are the arrow data, *X* and *Y* set the locaiton of the +arrows, and *C* sets the color of the arrows. These arguments may be 1-D or +2-D arrays or sequences. + +If *X* and *Y* are absent, they will be generated as a uniform grid. +If *U* and *V* are 2-D arrays and *X* and *Y* are 1-D, and if ``len(X)`` and +``len(Y)`` match the column and row dimensions of *U*, then *X* and *Y* will be expanded with :func:`numpy.meshgrid`. -*U*, *V*, *C* may be masked arrays, but masked *X*, *Y* are not -supported at present. +The default settings auto-scales the length of the arrows to a reasonable size. +To change this behavior see the *scale* and *scale_units* kwargs. The defaults give a slightly swept-back arrow; to make the head a triangle, make *headaxislength* the same as *headlength*. To make the @@ -61,30 +64,31 @@ scale down all the head parameters. You will probably do best to leave minshaft alone. -linewidths and edgecolors can be used to customize the arrow +*linewidths* and *edgecolors* can be used to customize the arrow outlines. Parameters ---------- -X : array, optional +X : 1D or 2D array, sequence, optional The x coordinates of the arrow locations -Y : array, optional +Y : 1D or 2D array, sequence, optional The y coordinates of the arrow locations -U : array +U : 1D or 2D array or masked array, sequence The x components of the arrow vectors -V : array +V : 1D or 2D array or masked array, sequence The y components of the arrow vectors -C : array, optional +C : 1D or 2D array, sequence, optional The arrow colors units : [ 'width' | 'height' | 'dots' | 'inches' | 'x' | 'y' | 'xy' ] - Arrow units; the arrow dimensions *except for length* are in - multiples of this unit + The arrow dimensions (except for *length*) are measured in multiples of + this unit. - *width* or *height*: the width or height of the axis + 'width' or 'height': the width or height of the axis - *dots* or *inches*: pixels or inches, based on the figure dpi + 'dots' or 'inches': pixels or inches, based on the figure dpi - *x*, *y*, or *xy*: *X*, *Y*, or sqrt(X^2+Y^2) data units + 'x', 'y', or 'xy': respectively *X*, *Y*, or :math:`\sqrt{X^2 + Y^2}` + in data units The arrows scale differently depending on the units. For 'x' or 'y', the arrows get larger as one zooms in; for other @@ -93,32 +97,42 @@ height of the axes, respectively, when the window is resized; for 'dots' or 'inches', resizing does not change the arrows. angles : [ 'uv' | 'xy' ], array, optional - With the default *uv*, the arrow axis aspect ratio is 1, so that + Method for determining the angle of the arrows. Default is 'uv'. + + 'uv': the arrow axis aspect ratio is 1 so that if *U*==*V* the orientation of the arrow on the plot is 45 degrees - CCW from the horizontal axis (positive to the right). - With 'xy', the arrow points from (x,y) to (x+u, y+v). + counter-clockwise from the horizontal axis (positive to the right). + + 'xy': arrows point from (x,y) to (x+u, y+v). Use this for plotting a gradient field, for example. + Alternatively, arbitrary angles may be specified as an array - of values in degrees, CCW from the horizontal axis. + of values in degrees, counter-clockwise from the horizontal axis. + Note: inverting a data axis will correspondingly invert the - arrows *only* with `angles='xy'`. + arrows only with ``angles='xy'```. scale : None, float, optional - Data units per arrow length unit, e.g., m/s per plot width; a smaller - scale parameter makes the arrow longer. If *None*, a simple - autoscaling algorithm is used, based on the average vector length - and the number of vectors. The arrow length unit is given by + Number of data units per arrow length unit, e.g., m/s per plot width; a + smaller scale parameter makes the arrow longer. Default is *None*. + + If *None*, a simple autoscaling algorithm is used, based on the average + vector length and the number of vectors. The arrow length unit is given by the *scale_units* parameter -scale_units : [ 'width' | 'height' | 'dots' | 'inches' | 'x' | 'y' | 'xy' ], None, optional - For example, if *scale_units* is 'inches', *scale* is 2.0, and +scale_units : [ 'width' | 'height' | 'dots' | 'inches' | 'x' | 'y' | 'xy' ], \ +None, optional + If the *scale* kwarg is *None*, the arrow length unit. Default is *None*. + + e.g. *scale_units* is 'inches', *scale* is 2.0, and ``(u,v) = (1,0)``, then the vector will be 0.5 inches long. - If *scale_units* is 'width', then the vector will be half the width - of the axes. + + If *scale_units* is 'width'/'height', then the vector will be half the + width/height of the axes. If *scale_units* is 'x' then the vector will be 0.5 x-axis - units. To plot vectors in the x-y plane, with u and v having + units. To plot vectors in the x-y plane, with u and v having the same units as x and y, use - "angles='xy', scale_units='xy', scale=1". -width : optional + ``angles='xy', scale_units='xy', scale=1``. +width : scalar, optional Shaft width in arrow units; default depends on choice of units, above, and number of vectors; a typical starting value is about 0.005 times the width of the plot. @@ -151,6 +165,9 @@ %(PolyCollection)s +See Also +-------- +quiverkey : Add a key to a quiver plot """ % docstring.interpd.params _quiverkey_doc = """ From 649eb6d1f597eaffbb869c72cc2b8640a5ffdfd0 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 22 Jan 2017 12:40:37 +0000 Subject: [PATCH 03/11] Add a simple quiver example --- examples/pylab_examples/quiver_simple_demo.py | 14 ++++++++++++++ lib/matplotlib/quiver.py | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 examples/pylab_examples/quiver_simple_demo.py diff --git a/examples/pylab_examples/quiver_simple_demo.py b/examples/pylab_examples/quiver_simple_demo.py new file mode 100644 index 000000000000..561bec6de65e --- /dev/null +++ b/examples/pylab_examples/quiver_simple_demo.py @@ -0,0 +1,14 @@ +'''A simple example of a quiverplt, with a quiverkey.''' +import matplotlib.pyplot as plt +import numpy as np + +X = np.arange(-10, 10, 1) +Y = np.arange(-10, 10, 1) +U, V = np.meshgrid(X, Y) + +fig, ax = plt.subplots() +q = ax.quiver(X, Y, U, V) +ax.quiverkey(q, X=0.3, Y=1.1, U=10, + label='Quiver key, length = 10', labelpos='E') + +plt.show() diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index 085ac94f4583..d889926e6c7c 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -110,7 +110,7 @@ of values in degrees, counter-clockwise from the horizontal axis. Note: inverting a data axis will correspondingly invert the - arrows only with ``angles='xy'```. + arrows only with ``angles='xy'``. scale : None, float, optional Number of data units per arrow length unit, e.g., m/s per plot width; a smaller scale parameter makes the arrow longer. Default is *None*. @@ -165,6 +165,10 @@ %(PolyCollection)s +Examples +-------- +.. plot:: mpl_examples/pylab_examples/quiver_simple_demo.py + See Also -------- quiverkey : Add a key to a quiver plot From 0e6b08ef6bfe7f1f41f2b9f27268fa321210340d Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 22 Jan 2017 13:05:20 +0000 Subject: [PATCH 04/11] Fix small typo in simple quiver demo --- examples/pylab_examples/quiver_simple_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pylab_examples/quiver_simple_demo.py b/examples/pylab_examples/quiver_simple_demo.py index 561bec6de65e..f30aa06f30ee 100644 --- a/examples/pylab_examples/quiver_simple_demo.py +++ b/examples/pylab_examples/quiver_simple_demo.py @@ -1,4 +1,4 @@ -'''A simple example of a quiverplt, with a quiverkey.''' +'''A simple example of a quiver plot, with a quiverkey.''' import matplotlib.pyplot as plt import numpy as np From a63fd7faf6f3b73d46ecc04e43c03393587d93c9 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 23 Jan 2017 18:35:13 +0000 Subject: [PATCH 05/11] Remove old simple quiver demo --- examples/pylab_examples/quiver_demo.py | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index 72bb275808be..abb4e980de29 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -1,12 +1,10 @@ ''' -Demonstration of quiver and quiverkey functions. This is using the -new version coming from the code in quiver.py. +Demonstration of advanced quiver and quiverkey functions. Known problem: the plot autoscaling does not take into account the arrows, so those on the boundaries are often out of the picture. This is *not* an easy problem to solve in a perfectly general way. The workaround is to manually expand the axes. - ''' import matplotlib.pyplot as plt import numpy as np @@ -16,18 +14,6 @@ U = np.cos(X) V = np.sin(Y) -# 1 -plt.figure() -Q = plt.quiver(U, V) -qk = plt.quiverkey(Q, 0.5, 0.98, 2, r'$2 \frac{m}{s}$', labelpos='W', - fontproperties={'weight': 'bold'}) -l, r, b, t = plt.axis() -dx, dy = r - l, t - b -plt.axis([l - 0.05*dx, r + 0.05*dx, b - 0.05*dy, t + 0.05*dy]) - -plt.title('Minimal arguments, no kwargs') - -# 2 plt.figure() Q = plt.quiver(X, Y, U, V, units='width') qk = plt.quiverkey(Q, 0.9, 0.95, 2, r'$2 \frac{m}{s}$', @@ -37,7 +23,6 @@ plt.axis([-1, 7, -1, 7]) plt.title('scales with plot width, not view') -# 3 plt.figure() Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], pivot='mid', color='r', units='inches') @@ -47,7 +32,6 @@ plt.axis([-1, 7, -1, 7]) plt.title("pivot='mid'; every third arrow; units='inches'") -# 4 plt.figure() M = np.hypot(U, V) Q = plt.quiver(X, Y, U, V, M, @@ -62,7 +46,6 @@ plt.axis([-1, 7, -1, 7]) plt.title("scales with x view; pivot='tip'") -# 5 plt.figure() Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], color='r', units='x', @@ -72,7 +55,6 @@ plt.axis([-1, 7, -1, 7]) plt.title("triangular head; scale with x view; black edges") -# 6 plt.figure() M = np.zeros(U.shape, dtype='bool') XMaskStart = U.shape[0]//3 @@ -85,7 +67,7 @@ U = ma.masked_array(U, mask=M) V = ma.masked_array(V, mask=M) Q = plt.quiver(U, V) -qk = plt.quiverkey(Q, 0.5, 0.98, 2, r'$2 \frac{m}{s}$', labelpos='W', +qk = plt.quiverkey(Q, 0.5, 0.96, 2, r'$2 \frac{m}{s}$', labelpos='W', fontproperties={'weight': 'bold'}) l, r, b, t = plt.axis() dx, dy = r - l, t - b From 25214c9479a02cc0d77e2f79e9cdd14181948316 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 28 Jan 2017 12:02:11 +0000 Subject: [PATCH 06/11] PEP8 + move titles to to of quiver_demo --- examples/pylab_examples/quiver_demo.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index abb4e980de29..0d3b82ef2d98 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -15,24 +15,25 @@ V = np.sin(Y) plt.figure() +plt.title('scales with plot width, not view') Q = plt.quiver(X, Y, U, V, units='width') qk = plt.quiverkey(Q, 0.9, 0.95, 2, r'$2 \frac{m}{s}$', labelpos='E', coordinates='figure', fontproperties={'weight': 'bold'}) plt.axis([-1, 7, -1, 7]) -plt.title('scales with plot width, not view') plt.figure() +plt.title("pivot='mid'; every third arrow; units='inches'") Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], pivot='mid', color='r', units='inches') qk = plt.quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'}) plt.plot(X[::3, ::3], Y[::3, ::3], 'k.') plt.axis([-1, 7, -1, 7]) -plt.title("pivot='mid'; every third arrow; units='inches'") plt.figure() +plt.title("scales with x view; pivot='tip'") M = np.hypot(U, V) Q = plt.quiver(X, Y, U, V, M, units='x', @@ -44,23 +45,25 @@ fontproperties={'weight': 'bold'}) plt.plot(X, Y, 'k.', markersize=2) plt.axis([-1, 7, -1, 7]) -plt.title("scales with x view; pivot='tip'") plt.figure() +plt.title("triangular head; scale with x view; black edges") + Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], color='r', units='x', linewidths=(0.5,), edgecolors=('k'), headaxislength=5) qk = plt.quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'}) plt.axis([-1, 7, -1, 7]) -plt.title("triangular head; scale with x view; black edges") plt.figure() +plt.title('Minimal arguments, no kwargs - masked values') + M = np.zeros(U.shape, dtype='bool') -XMaskStart = U.shape[0]//3 -YMaskStart = U.shape[1]//3 -XMaskStop = 2*U.shape[0]//3 -YMaskStop = 2*U.shape[1]//3 +XMaskStart = U.shape[0] // 3 +YMaskStart = U.shape[1] // 3 +XMaskStop = 2 * U.shape[0] // 3 +YMaskStop = 2 * U.shape[1] // 3 M[XMaskStart:XMaskStop, YMaskStart:YMaskStop] = True @@ -72,7 +75,5 @@ l, r, b, t = plt.axis() dx, dy = r - l, t - b plt.axis([l - 0.05 * dx, r + 0.05 * dx, b - 0.05 * dy, t + 0.05 * dy]) -plt.title('Minimal arguments, no kwargs - masked values') - plt.show() From 8aa1c8287219938990225e14c11b770017f3985a Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 28 Jan 2017 12:30:13 +0000 Subject: [PATCH 07/11] Remove extra comma --- examples/pylab_examples/quiver_simple_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pylab_examples/quiver_simple_demo.py b/examples/pylab_examples/quiver_simple_demo.py index f30aa06f30ee..0d92a61ab405 100644 --- a/examples/pylab_examples/quiver_simple_demo.py +++ b/examples/pylab_examples/quiver_simple_demo.py @@ -1,4 +1,4 @@ -'''A simple example of a quiver plot, with a quiverkey.''' +'''A simple example of a quiver plot with a quiverkey.''' import matplotlib.pyplot as plt import numpy as np From b853fec8f554ae6318de7b16a11066add08eb405 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 28 Jan 2017 12:30:39 +0000 Subject: [PATCH 08/11] Remove masked values quiver example --- examples/pylab_examples/quiver_demo.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index 0d3b82ef2d98..96bc94ecf011 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -56,24 +56,4 @@ fontproperties={'weight': 'bold'}) plt.axis([-1, 7, -1, 7]) -plt.figure() -plt.title('Minimal arguments, no kwargs - masked values') - -M = np.zeros(U.shape, dtype='bool') -XMaskStart = U.shape[0] // 3 -YMaskStart = U.shape[1] // 3 -XMaskStop = 2 * U.shape[0] // 3 -YMaskStop = 2 * U.shape[1] // 3 - -M[XMaskStart:XMaskStop, - YMaskStart:YMaskStop] = True -U = ma.masked_array(U, mask=M) -V = ma.masked_array(V, mask=M) -Q = plt.quiver(U, V) -qk = plt.quiverkey(Q, 0.5, 0.96, 2, r'$2 \frac{m}{s}$', labelpos='W', - fontproperties={'weight': 'bold'}) -l, r, b, t = plt.axis() -dx, dy = r - l, t - b -plt.axis([l - 0.05 * dx, r + 0.05 * dx, b - 0.05 * dy, t + 0.05 * dy]) - plt.show() From 96b8e00fd6f0e61c96535677934b9ed71e68852e Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 28 Jan 2017 12:31:44 +0000 Subject: [PATCH 09/11] Remove quiver example that only differs in arrow style --- examples/pylab_examples/quiver_demo.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index 96bc94ecf011..0ec39b40c878 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -46,14 +46,4 @@ plt.plot(X, Y, 'k.', markersize=2) plt.axis([-1, 7, -1, 7]) -plt.figure() -plt.title("triangular head; scale with x view; black edges") - -Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], - color='r', units='x', - linewidths=(0.5,), edgecolors=('k'), headaxislength=5) -qk = plt.quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', - fontproperties={'weight': 'bold'}) -plt.axis([-1, 7, -1, 7]) - plt.show() From fdffaf6d6f4bd9b786a1d22a9fbb6d21cb1837a5 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 28 Jan 2017 12:44:27 +0000 Subject: [PATCH 10/11] Simplify remaining quiver examples --- examples/pylab_examples/quiver_demo.py | 33 ++++++++++---------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index 0ec39b40c878..64cd54f26bdf 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -15,35 +15,26 @@ V = np.sin(Y) plt.figure() -plt.title('scales with plot width, not view') +plt.title('Arrows scale with plot width, not view') Q = plt.quiver(X, Y, U, V, units='width') -qk = plt.quiverkey(Q, 0.9, 0.95, 2, r'$2 \frac{m}{s}$', - labelpos='E', - coordinates='figure', - fontproperties={'weight': 'bold'}) -plt.axis([-1, 7, -1, 7]) +qk = plt.quiverkey(Q, 0.9, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E', + coordinates='figure') plt.figure() plt.title("pivot='mid'; every third arrow; units='inches'") Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], - pivot='mid', color='r', units='inches') -qk = plt.quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', - fontproperties={'weight': 'bold'}) -plt.plot(X[::3, ::3], Y[::3, ::3], 'k.') -plt.axis([-1, 7, -1, 7]) + pivot='mid', units='inches') +qk = plt.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E', + coordinates='figure') +plt.scatter(X[::3, ::3], Y[::3, ::3], color='r', s=5) plt.figure() -plt.title("scales with x view; pivot='tip'") +plt.title("pivot='tip'; scales with x view") M = np.hypot(U, V) -Q = plt.quiver(X, Y, U, V, M, - units='x', - pivot='tip', - width=0.022, +Q = plt.quiver(X, Y, U, V, M, units='x', pivot='tip', width=0.022, scale=1 / 0.15) -qk = plt.quiverkey(Q, 0.9, 1.05, 1, r'$1 \frac{m}{s}$', - labelpos='E', - fontproperties={'weight': 'bold'}) -plt.plot(X, Y, 'k.', markersize=2) -plt.axis([-1, 7, -1, 7]) +qk = plt.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E', + coordinates='figure') +plt.scatter(X, Y, color='k', s=5) plt.show() From 485078ab416a89cdbdd657d79dbea65c57660320 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 29 Jan 2017 19:32:44 +0000 Subject: [PATCH 11/11] Add example titles --- examples/pylab_examples/quiver_demo.py | 4 +++- examples/pylab_examples/quiver_simple_demo.py | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index 64cd54f26bdf..067d6029e82d 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -1,5 +1,7 @@ ''' -Demonstration of advanced quiver and quiverkey functions. +======================================================== +Demonstration of advanced quiver and quiverkey functions +======================================================== Known problem: the plot autoscaling does not take into account the arrows, so those on the boundaries are often out of the picture. diff --git a/examples/pylab_examples/quiver_simple_demo.py b/examples/pylab_examples/quiver_simple_demo.py index 0d92a61ab405..417b9c2b03ad 100644 --- a/examples/pylab_examples/quiver_simple_demo.py +++ b/examples/pylab_examples/quiver_simple_demo.py @@ -1,4 +1,8 @@ -'''A simple example of a quiver plot with a quiverkey.''' +''' +================================================== +A simple example of a quiver plot with a quiverkey +================================================== +''' import matplotlib.pyplot as plt import numpy as np