Skip to content

Streamplot ignores rightmost column and topmost row of velocity data #11452

@pmackenz

Description

@pmackenz

Bug report

Bug summary

streamplot ignores the rightmost column (and topmost row) in U and V and replaces them by a copy of the second to last column (row). This yields wrong stream lines in the rightmost column and topmost row of cells. The issue is most noticeable on coarse grids. (see example plots)

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-1, 1, 3)
y = np.linspace(0, 1, 2)

U = np.array([[.2,.2,.2],[.2,1,.2]])
V = np.array([[-1,2,-1],[-1,0.,-1]])

plt.streamplot(x,y, U,V)
plt.quiver(x,y, U,V)
plt.xlim(-1.5,1.5)
plt.ylim(-0.5,1.5)
plt.savefig('StreamPlotIssue1.png')
plt.close()

x = np.linspace(-1, 1, 5)
y = np.linspace(0, 1, 4)

U = np.array([[.2,.2,.2,.2,.2],[.2,.2,.2,.2,.2],[.2,.2,.2,.2,.2],[.2,1.,1.,1,.2]])
V = np.array([[-1,.5,2,.5,-1],[-1,.5,2,.5,-1],[-1,.5,2,.5,-1],[-1,0.,0.,0.,-1]])

plt.streamplot(x,y, U,V)
plt.quiver(x,y, U,V)
plt.xlim(-1.5,1.5)
plt.ylim(-0.5,1.5)
plt.savefig('StreamPlotIssue2.png')
plt.close()

Actual outcome

The first image uses just 2 cells (2 in x, 1 in y direction). The field should create an antisymmetric wave. The left cell is OK, the right one is garbage. (The example is chosen such that the top row issue doesn't show too badly). The overlaid quiver plot shows the correct velocity.

streamplotissue1

The second image uses 4 cells in x and 3 cells in y-direction for the same velocity field. Quiver shows the correct velocity as overlay. The rightmost column and top row of cells show the wrong streamlines.

streamplotissue2

For quick reference: the variables used

# image 1
#x:
[-1.  0.  1.]
# y:
[0. 1.]
# U:
[[0.2 0.2 0.2]
 [0.2 1.  0.2]]
# V:
[[-1.  2. -1.]
 [-1.  0. -1.]]

# image 2

#x:
[-1.  -0.5  0.   0.5  1. ]
# y:
[0.         0.33333333 0.66666667 1.        ]
# U:
[[0.2 0.2 0.2 0.2 0.2]
 [0.2 0.2 0.2 0.2 0.2]
 [0.2 0.2 0.2 0.2 0.2]
 [0.2 1.  1.  1.  0.2]]
# V:
[[-1.   0.5  2.   0.5 -1. ]
 [-1.   0.5  2.   0.5 -1. ]
 [-1.   0.5  2.   0.5 -1. ]
 [-1.   0.   0.   0.  -1. ]]

Expected outcome

A streamline plot consistent with velocity shown in quiver overlay.

Matplotlib version

  • Operating system:
    MacOS High Sierra (10.13.5)
  • Matplotlib version:
    matplotlib-2.1.2-py36h6d6146d_0
  • Matplotlib backend (print(matplotlib.get_backend())):
    MacOSX
  • Python version:
    3.6
  • Jupyter version (if applicable):
    n/a
  • Other libraries:
    numpy

Python and matplotlib installed using anaconda3 package

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions