Streamplot - Streamlines in Julia

Hello,

I have this MATLAB code (arrays are examples)

XX =[0.0 0.0 0.0; 0.5 0.5 0.5; 1.0 1.0 1.0];
YY = [0.0 0.5 1.0; 0.0 0.5 1.0; 0.0 0.5 1.0];
U = [-0.0 -0.0 0.0; -0.0 -0.6 0.0; -0.0 -9.184850993605148e-17 0.0];
V = [0.9999999999999966 1.0 1.0; 1.0000000000000002 0.7999999999999999 0.9999999999999999; 1.0 1.0 0.9999999999999966];

streamline(XX, YY, U, V)

And I want the same plot in Julia. I’ve seen streamplot from GLMakie, but arguments are limits and a function. How to do ?
I have this code but it’s useless because I don’t use XX, YY, U and V

XX = [0.0 0.0 0.0; 0.5 0.5 0.5; 1.0 1.0 1.0]
YY = [0.0 0.5 1.0; 0.0 0.5 1.0; 0.0 0.5 1.0]
U = [-0.0 -0.0 0.0; -0.0 -0.6 0.0; -0.0 -9.184850993605148e-17 0.0]
V = [0.9999999999999966 1.0 1.0; 1.0000000000000002 0.7999999999999999 0.9999999999999999; 1.0 1.0 0.9999999999999966]

using GLMakie 

odeSol(x,y) = Point(-x, -y)             # x'(t) = -x, y'(t) = 2y
fig = Figure(resolution =(400,400))
ax = Axis(fig)
streamplot!(ax, odeSol, -2..2, -2..2, colormap = :plasma, 
    gridsize= (32,32), arrow_size = 0.07)
fig[1,1] = ax
fig

Thank you

Why are those matrices?

Is this maybe what you’re looking for?

arrows(vec(XX), vec(YY), vec(U), vec(V))

https://docs.makie.org/stable/examples/plotting_functions/arrows/index.html#arrows

Sorry, my MATLAB code is false…
This is the working code !

clear all;
XX = unique([0.0 0.0 0.0; 0.5 0.5 0.5; 1.0 1.0 1.0]);
YY = unique([0.0 0.5 1.0; 0.0 0.5 1.0; 0.0 0.5 1.0]);
U = [-0.0 -0.0 0.0; -0.0 -0.6 0.0; -0.0 -9.184850993605148e-17 0.0];
V = [0.9999999999999966 1.0 1.0; 1.0000000000000002 0.7999999999999999 0.9999999999999999; 1.0 1.0 0.9999999999999966];
startx = linspace(0,1,50);
starty = zeros(size(startx));

streamline(XX, YY, U, V, startx, starty)

And this is what is expected.
image

Those matrices are a sample of my code to test with Julia without reload my code and to share only essential.
The problem with arrows is, that’s not continuous. Or in all case, I don’t know how to do

GMT works like in Matlab. With that exact input and noting that it is streamlines instead of streamline

using GMT

s = streamlines(XX, YY, U, V, startx, starty);
plot(s, show=1)

2 Likes

It works, thanks !

This is the code :

using GMT

X = range(0, stop = 1, length = 3)
Y = range(0, stop = 1, length = 3)
XX, YY = GMT.meshgrid(X, Y) # We must to convert, it's the same XX and YY than before

u = [-0.0 -0.0 0.0; -0.0 -0.6 0.0; -0.0 0.0 0.0]
v = [1.0 1.0 1.0; 1.0 0.8 1.0; 1.0 1.0 1.0]

U = mat2grid(u, XX[1, :], YY[:, 1])
V = mat2grid(v, XX[1, :], YY[:, 1])

startx = linspace(0,1,50);
starty = zeros(length(startx));
p = streamlines(U, V, startx, starty) 
plot(p, show = true)
1 Like