Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e795c9

Browse files
committed
Fixed quiver to account for zero magnitude vectors
svn path=/trunk/matplotlib/; revision=1790
1 parent bc6186c commit 4e795c9

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -853,10 +853,10 @@ def quiver(self, U, V, *args, **kwargs ):
853853
arrows = []
854854
N = sqrt( U**2+V**2 )
855855
if do_scale:
856-
Nmax = maximum.reduce(maximum.reduce(N))
857-
U *= (S/Nmax)
858-
V *= (S/Nmax)
859-
N /= Nmax
856+
Nmax = maximum.reduce(maximum.reduce(N)) or 1 # account for div by zero
857+
U = U*(S/Nmax)
858+
V = V*(S/Nmax)
859+
N = N*Nmax
860860

861861
alpha = kwargs.get('alpha', 1.0)
862862
width = kwargs.get('width', 0.25)
@@ -890,7 +890,7 @@ def quiver(self, U, V, *args, **kwargs ):
890890
arrows,
891891
edgecolors = 'None',
892892
facecolors = (color,),
893-
antialiaseds = (0,),
893+
antialiaseds = (1,),
894894
linewidths = (width,),
895895
)
896896
if C is not None:

lib/matplotlib/patches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def __init__( self, x, y, dx, dy, width=1.0, **kwargs ):
398398
[ 0.8, -0.1 ], [ 0.8, -0.3],
399399
[ 1.0, 0.0 ], [ 0.8, 0.3],
400400
[ 0.8, 0.1 ] ] )
401-
L = sqrt(dx**2+dy**2)
401+
L = sqrt(dx**2+dy**2) or 1 # account for div by zero
402402
arrow[:,0] *= L
403403
arrow[:,1] *= width
404404
cx = float(dx)/L

0 commit comments

Comments
 (0)