From a204ae0dc0c4bf4a5ec5e40c67512eaa13f2ef30 Mon Sep 17 00:00:00 2001 From: DanHickstein Date: Tue, 10 Nov 2015 11:14:24 -0700 Subject: [PATCH 01/10] Removed normalization of arrows in 3D quiver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I removed the normalization of the arrows in 3D quiver to match the behavior of the 2D quiver plot. Also, I changed the default pivot point to be ‘tail’ in order to match the 2D quiver plot. Also, clarified the comment about normalizing the ‘uvw’ variable. --- lib/mpl_toolkits/mplot3d/axes3d.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 912722bc4583..1960228c99d6 100755 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -2477,7 +2477,7 @@ def quiver(self, *args, **kwargs): *X*, *Y*, *Z*: The x, y and z coordinates of the arrow locations (default is - tip of arrow; see *pivot* kwarg) + tail of arrow; see *pivot* kwarg) *U*, *V*, *W*: The x, y and z components of the arrow vectors @@ -2499,7 +2499,8 @@ def quiver(self, *args, **kwargs): *pivot*: [ 'tail' | 'middle' | 'tip' ] The part of the arrow that is at the grid point; the arrow - rotates about this point, hence the name *pivot*. + rotates about this point, hence the name *pivot*. + Default is 'tail' Any additional keyword arguments are delegated to :class:`~matplotlib.collections.LineCollection` @@ -2508,6 +2509,7 @@ def quiver(self, *args, **kwargs): def calc_arrow(uvw, angle=15): """ To calculate the arrow head. uvw should be a unit vector. + We normalize it here: """ # get unit direction vector perpendicular to (u,v,w) norm = np.linalg.norm(uvw[:2]) @@ -2540,7 +2542,7 @@ def calc_arrow(uvw, angle=15): # arrow length ratio to the shaft length arrow_length_ratio = kwargs.pop('arrow_length_ratio', 0.3) # pivot point - pivot = kwargs.pop('pivot', 'tip') + pivot = kwargs.pop('pivot', 'tail') # handle args argi = 6 @@ -2601,7 +2603,7 @@ def calc_arrow(uvw, angle=15): # If any row of UVW is all zeros, don't make a quiver for it mask = norm > 1e-10 XYZ = XYZ[mask] - UVW = UVW[mask] / norm[mask].reshape((-1, 1)) + UVW = UVW[mask] if len(XYZ) > 0: # compute the shaft lines all at once with an outer product From ff2a207da4ca3cee92f081f66528f34546ac8c88 Mon Sep 17 00:00:00 2001 From: DanHickstein Date: Tue, 10 Nov 2015 12:27:43 -0700 Subject: [PATCH 02/10] Included an option to normalize --- lib/mpl_toolkits/mplot3d/axes3d.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 1960228c99d6..092b315a4ed6 100755 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -2543,6 +2543,8 @@ def calc_arrow(uvw, angle=15): arrow_length_ratio = kwargs.pop('arrow_length_ratio', 0.3) # pivot point pivot = kwargs.pop('pivot', 'tail') + # normalize + pivot = kwargs.pop('normalize', False) # handle args argi = 6 @@ -2603,7 +2605,10 @@ def calc_arrow(uvw, angle=15): # If any row of UVW is all zeros, don't make a quiver for it mask = norm > 1e-10 XYZ = XYZ[mask] - UVW = UVW[mask] + if normalize == True: + UVW = UVW[mask]/ norm[mask].reshape((-1, 1)) + else: + UVW = UVW[mask] if len(XYZ) > 0: # compute the shaft lines all at once with an outer product From 0f75d916c1c583e111ea7cc3fa3d9bdfeb60dfe0 Mon Sep 17 00:00:00 2001 From: DanHickstein Date: Tue, 10 Nov 2015 13:02:16 -0700 Subject: [PATCH 03/10] Simplified to "if normalize" and fixed typo also added a space before division. Also --- lib/mpl_toolkits/mplot3d/axes3d.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 092b315a4ed6..94451c334a73 100755 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -2544,7 +2544,7 @@ def calc_arrow(uvw, angle=15): # pivot point pivot = kwargs.pop('pivot', 'tail') # normalize - pivot = kwargs.pop('normalize', False) + normalize = kwargs.pop('normalize', False) # handle args argi = 6 @@ -2605,8 +2605,8 @@ def calc_arrow(uvw, angle=15): # If any row of UVW is all zeros, don't make a quiver for it mask = norm > 1e-10 XYZ = XYZ[mask] - if normalize == True: - UVW = UVW[mask]/ norm[mask].reshape((-1, 1)) + if normalize: + UVW = UVW[mask] / norm[mask].reshape((-1, 1)) else: UVW = UVW[mask] From 8ac7544dd33bb3fd25434d9f336a793a95ec7d3a Mon Sep 17 00:00:00 2001 From: DanHickstein Date: Tue, 10 Nov 2015 13:05:46 -0700 Subject: [PATCH 04/10] Included "normalize=True" to the quiver3d_demo --- examples/mplot3d/quiver3d_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/mplot3d/quiver3d_demo.py b/examples/mplot3d/quiver3d_demo.py index 1051c2fe3ff1..a0a0a2b8f064 100644 --- a/examples/mplot3d/quiver3d_demo.py +++ b/examples/mplot3d/quiver3d_demo.py @@ -14,6 +14,6 @@ w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) * np.sin(np.pi * z)) -ax.quiver(x, y, z, u, v, w, length=0.1) +ax.quiver(x, y, z, u, v, w, length=0.1,normalize=True) plt.show() From c853111f167354fe24760745059c6ed5f58f9fa1 Mon Sep 17 00:00:00 2001 From: DanHickstein Date: Tue, 10 Nov 2015 17:05:25 -0700 Subject: [PATCH 05/10] updated quiver3d tests to use pivot='tip' and normalize=True --- examples/mplot3d/quiver3d_demo.py | 2 +- lib/mpl_toolkits/tests/test_mplot3d.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/mplot3d/quiver3d_demo.py b/examples/mplot3d/quiver3d_demo.py index a0a0a2b8f064..65d02862db8a 100644 --- a/examples/mplot3d/quiver3d_demo.py +++ b/examples/mplot3d/quiver3d_demo.py @@ -14,6 +14,6 @@ w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) * np.sin(np.pi * z)) -ax.quiver(x, y, z, u, v, w, length=0.1,normalize=True) +ax.quiver(x, y, z, u, v, w, length=0.1, normalize=True) plt.show() diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index 4dbf4c0e6912..86f62af9fd8f 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -215,7 +215,7 @@ def test_quiver3d(): w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) * np.sin(np.pi * z)) - ax.quiver(x, y, z, u, v, w, length=0.1) + ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True) @image_comparison(baseline_images=['quiver3d_empty'], remove_text=True) def test_quiver3d_empty(): @@ -229,7 +229,7 @@ def test_quiver3d_empty(): w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) * np.sin(np.pi * z)) - ax.quiver(x, y, z, u, v, w, length=0.1) + ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True) @image_comparison(baseline_images=['quiver3d_masked'], remove_text=True) def test_quiver3d_masked(): @@ -247,7 +247,7 @@ def test_quiver3d_masked(): u = np.ma.masked_where((-0.4 < x) & (x < 0.1), u, copy=False) v = np.ma.masked_where((0.1 < y) & (y < 0.7), v, copy=False) - ax.quiver(x, y, z, u, v, w, length=0.1) + ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tip', normalize=True) @image_comparison(baseline_images=['quiver3d_pivot_middle'], remove_text=True, extensions=['png']) @@ -262,7 +262,7 @@ def test_quiver3d_pivot_middle(): w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) * np.sin(np.pi * z)) - ax.quiver(x, y, z, u, v, w, length=0.1, pivot='middle') + ax.quiver(x, y, z, u, v, w, length=0.1, pivot='middle', normalize=True) @image_comparison(baseline_images=['quiver3d_pivot_tail'], remove_text=True, extensions=['png']) @@ -277,7 +277,7 @@ def test_quiver3d_pivot_tail(): w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) * np.sin(np.pi * z)) - ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tail') + ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tail', normalize=True) @image_comparison(baseline_images=['axes3d_labelpad'], extensions=['png']) From 2edbf13355f2949b445804d16a0d30006d21a1e7 Mon Sep 17 00:00:00 2001 From: DanHickstein Date: Thu, 12 Nov 2015 18:22:49 -0700 Subject: [PATCH 06/10] added documentation of the api change to doc/api/api_changes --- doc/api/api_changes/2015-11-12-DDH.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 doc/api/api_changes/2015-11-12-DDH.rst diff --git a/doc/api/api_changes/2015-11-12-DDH.rst b/doc/api/api_changes/2015-11-12-DDH.rst new file mode 100644 index 000000000000..5a83660e6069 --- /dev/null +++ b/doc/api/api_changes/2015-11-12-DDH.rst @@ -0,0 +1,16 @@ +Modified the 3D quiver function in mpl_toolkits.mplot3d.axes3d.py to have the dafaults: normalize=False, pivot='tail' +``````````````````````````` +Matplotlib has both a 2D and a 3D "quiver" function. These changes affect only the 3D function and make the default behavior of the 3D function match 2D version. There are two main changes: + +1) The 3D quiver function previously normalized the arrows to be the same length, which makes it unusable for situations where the arrows should be different lengths and does not match the behavior of the 2D function. This normalization behavior is now controlled with the "normalize" keyword, which defaults to False. + +2) The "pivot" keyword now defaults to "tail" insteaf of "tip". This was done in order to match the default behavior of the 2D quiver function. + +To obtain the previous behavior with the 3D quiver function, one can call the function with: + +ax.quiver(x, y, z, u, v, w, normalize=True, pivot='tip') + +where "ax" is a axes3d object created with something like: + +import mpl_toolkits.mplot3d.axes3d +ax = plt.sublot(111, projection='3d') \ No newline at end of file From 5bcf30265202ea7617d6bd076d4490619397c9b4 Mon Sep 17 00:00:00 2001 From: DanHickstein Date: Thu, 12 Nov 2015 21:14:56 -0700 Subject: [PATCH 07/10] Improved api change description Fixed typo, changed quotes, improved descriptions. --- doc/api/api_changes/2015-11-12-DDH.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/api/api_changes/2015-11-12-DDH.rst b/doc/api/api_changes/2015-11-12-DDH.rst index 5a83660e6069..7b3260f3afd3 100644 --- a/doc/api/api_changes/2015-11-12-DDH.rst +++ b/doc/api/api_changes/2015-11-12-DDH.rst @@ -1,16 +1,16 @@ -Modified the 3D quiver function in mpl_toolkits.mplot3d.axes3d.py to have the dafaults: normalize=False, pivot='tail' +New defaults for 3D quiver function in mpl_toolkits.mplot3d.axes3d.py ``````````````````````````` -Matplotlib has both a 2D and a 3D "quiver" function. These changes affect only the 3D function and make the default behavior of the 3D function match 2D version. There are two main changes: +Matplotlib has both a 2D and a 3D `quiver` function. These changes affect only the 3D function and make the default behavior of the 3D function match 2D version. There are two changes: -1) The 3D quiver function previously normalized the arrows to be the same length, which makes it unusable for situations where the arrows should be different lengths and does not match the behavior of the 2D function. This normalization behavior is now controlled with the "normalize" keyword, which defaults to False. +1) The 3D quiver function previously normalized the arrows to be the same length, which makes it unusable for situations where the arrows should be different lengths and does not match the behavior of the 2D function. This normalization behavior is now controlled with the `normalize` keyword, which defaults to False. -2) The "pivot" keyword now defaults to "tail" insteaf of "tip". This was done in order to match the default behavior of the 2D quiver function. +2) The `pivot` keyword now defaults to `tail` insteaf of `tip`. This was done in order to match the default behavior of the 2D quiver function. -To obtain the previous behavior with the 3D quiver function, one can call the function with: +To obtain the previous behavior with the 3D quiver function, one can call the function with :: -ax.quiver(x, y, z, u, v, w, normalize=True, pivot='tip') + ax.quiver(x, y, z, u, v, w, normalize=True, pivot='tip') -where "ax" is a axes3d object created with something like: +where "ax" is a axes3d object created with something like :: -import mpl_toolkits.mplot3d.axes3d -ax = plt.sublot(111, projection='3d') \ No newline at end of file + import mpl_toolkits.mplot3d.axes3d + ax = plt.sublot(111, projection='3d') \ No newline at end of file From 460104d6c9b74ed6008eb6b835fad20015579e29 Mon Sep 17 00:00:00 2001 From: DanHickstein Date: Fri, 13 Nov 2015 08:15:35 -0700 Subject: [PATCH 08/10] fixed backticks in api_changes --- doc/api/api_changes/2015-11-12-DDH.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api/api_changes/2015-11-12-DDH.rst b/doc/api/api_changes/2015-11-12-DDH.rst index 7b3260f3afd3..cc6505e8b96e 100644 --- a/doc/api/api_changes/2015-11-12-DDH.rst +++ b/doc/api/api_changes/2015-11-12-DDH.rst @@ -1,10 +1,10 @@ New defaults for 3D quiver function in mpl_toolkits.mplot3d.axes3d.py ``````````````````````````` -Matplotlib has both a 2D and a 3D `quiver` function. These changes affect only the 3D function and make the default behavior of the 3D function match 2D version. There are two changes: +Matplotlib has both a 2D and a 3D ```quiver``` function. These changes affect only the 3D function and make the default behavior of the 3D function match 2D version. There are two changes: -1) The 3D quiver function previously normalized the arrows to be the same length, which makes it unusable for situations where the arrows should be different lengths and does not match the behavior of the 2D function. This normalization behavior is now controlled with the `normalize` keyword, which defaults to False. +1) The 3D quiver function previously normalized the arrows to be the same length, which makes it unusable for situations where the arrows should be different lengths and does not match the behavior of the 2D function. This normalization behavior is now controlled with the ``normalize`` keyword, which defaults to False. -2) The `pivot` keyword now defaults to `tail` insteaf of `tip`. This was done in order to match the default behavior of the 2D quiver function. +2) The ``pivot`` keyword now defaults to ``tail`` insteaf of ```tip```. This was done in order to match the default behavior of the 2D quiver function. To obtain the previous behavior with the 3D quiver function, one can call the function with :: From 29c3ef6c48b2251e33cc7113d97ce3befe14e48d Mon Sep 17 00:00:00 2001 From: DanHickstein Date: Fri, 13 Nov 2015 08:16:44 -0700 Subject: [PATCH 09/10] fixed more typos in api_changes --- doc/api/api_changes/2015-11-12-DDH.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/api_changes/2015-11-12-DDH.rst b/doc/api/api_changes/2015-11-12-DDH.rst index cc6505e8b96e..ba899dc6e7f0 100644 --- a/doc/api/api_changes/2015-11-12-DDH.rst +++ b/doc/api/api_changes/2015-11-12-DDH.rst @@ -1,10 +1,10 @@ New defaults for 3D quiver function in mpl_toolkits.mplot3d.axes3d.py ``````````````````````````` -Matplotlib has both a 2D and a 3D ```quiver``` function. These changes affect only the 3D function and make the default behavior of the 3D function match 2D version. There are two changes: +Matplotlib has both a 2D and a 3D ``quiver`` function. These changes affect only the 3D function and make the default behavior of the 3D function match 2D version. There are two changes: 1) The 3D quiver function previously normalized the arrows to be the same length, which makes it unusable for situations where the arrows should be different lengths and does not match the behavior of the 2D function. This normalization behavior is now controlled with the ``normalize`` keyword, which defaults to False. -2) The ``pivot`` keyword now defaults to ``tail`` insteaf of ```tip```. This was done in order to match the default behavior of the 2D quiver function. +2) The ``pivot`` keyword now defaults to ``tail`` instead of ``tip``. This was done in order to match the default behavior of the 2D quiver function. To obtain the previous behavior with the 3D quiver function, one can call the function with :: From b81e976f6876104f750647c287ce0301731b2011 Mon Sep 17 00:00:00 2001 From: DanHickstein Date: Fri, 13 Nov 2015 17:28:32 -0700 Subject: [PATCH 10/10] Added documentation for the normalize keyword to the quiver function --- lib/mpl_toolkits/mplot3d/axes3d.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 94451c334a73..59ce4e6626f3 100755 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -2501,6 +2501,11 @@ def quiver(self, *args, **kwargs): The part of the arrow that is at the grid point; the arrow rotates about this point, hence the name *pivot*. Default is 'tail' + + *normalize*: [False | True] + When True, all of the arrows will be the same length. This + defaults to False, where the arrows will be different lengths + depending on the values of u,v,w. Any additional keyword arguments are delegated to :class:`~matplotlib.collections.LineCollection` pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy