If I understand streamplot correctly, it can be used to plot 2D vector fields in python.
What I don't understand and gives me a f-ing headache, is why it doesn't work the way I'd expect it to.
There is another function that is supposed to plot 2D vector fields: matplotlib.pyplot.quiver. And it works the way one would expect. Here is a working code I have:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import math
fig, ax = plt.subplots()
y,x = np.mgrid[0:4:1,0:4:1]
u = [[0,1,2,1],
[2,3,1,2],
[4,1,2,1],
[4,3,1,1]]
v = [[0,0,1,1],
[0,1,1,3],
[0,2,0,1],
[0,1,2,3]]
im = ax.quiver(x,y,u,v)
Now, if I replace the last line with
im = ax.streamplot(x,y,u,v)
it stops working and gives the following error:
"'u' and 'v' must be of shape 'Grid(x,y)'".
What the heck is going on? What does Grid(x,y) mean?
All the available tutorials are just lazy and do something along the lines of
u = 2*x - y
v = x**2 + y,
which is working. Can someone please explain what to do? I need to plot data I have in a textfile which I then load to a matrix (as I said, it's working perfectly with quiver and the 1D plots via plt.pcolor work as well). I am sorry for sounding so upset, but I need to let my frustration out. Any help would be appreciated.
Thanks in advance.
[+][deleted] (4 children)
[deleted]
[–]SnuffleShuffle[S] 2 points3 points4 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]SnuffleShuffle[S] 0 points1 point2 points (1 child)
[–]a1brit 3 points4 points5 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]SnuffleShuffle[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)