# Streamplot - Streamlines in Julia

**URL:** <https://discourse.julialang.org/t/streamplot-streamlines-in-julia/101537>\
**Category:** Visualization\
**Tags:** plotting, matlab, glmakie, gmt\
**Created:** [July 12, 2023, 2:29pm UTC](https://discourse.julialang.org/t/streamplot-streamlines-in-julia/101537 "2023-07-12T14:29:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sisisi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sisisi/32/51469_2.png) [@Sisisi](https://discourse.julialang.org/u/Sisisi)\
**Post date:** [July 12, 2023, 2:29pm UTC](https://discourse.julialang.org/t/streamplot-streamlines-in-julia/101537/1 "2023-07-12T14:29:56Z")

</div>

Hello,

I have this MATLAB code (arrays are examples)

```julia
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

```julia
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

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [July 12, 2023, 2:35pm UTC](https://discourse.julialang.org/t/streamplot-streamlines-in-julia/101537/2 "2023-07-12T14:35:28Z")

</div>

Why are those matrices?

Is this maybe what you’re looking for?

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

```

[https://docs.makie.org/stable/examples/plotting\_functions/arrows/index.html#arrows](https://docs.makie.org/stable/examples/plotting_functions/arrows/index.html#arrows)

---

<div class="post-metadata">

**Author:** ![Sisisi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sisisi/32/51469_2.png) [@Sisisi](https://discourse.julialang.org/u/Sisisi)\
**Post date:** [July 12, 2023, 5:57pm UTC](https://discourse.julialang.org/t/streamplot-streamlines-in-julia/101537/3 "2023-07-12T17:57:15Z")

</div>

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

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/b/2/b2fdacc8a6acad677d39f215288557aedee9dd99.png)

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

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [July 12, 2023, 6:42pm UTC](https://discourse.julialang.org/t/streamplot-streamlines-in-julia/101537/4 "2023-07-12T18:42:31Z")

</div>

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

```julia
using GMT

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

```

 ![str](https://global.discourse-cdn.com/julialang/original/3X/1/c/1c33978a0c934f07b1cb32b56faec3ae2d730e52.png)

---

<div class="post-metadata">

**Author:** ![Sisisi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sisisi/32/51469_2.png) [@Sisisi](https://discourse.julialang.org/u/Sisisi)\
**Post date:** [July 12, 2023, 7:51pm UTC](https://discourse.julialang.org/t/streamplot-streamlines-in-julia/101537/5 "2023-07-12T19:51:16Z")

</div>

It works, thanks !

This is the code :

```julia
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)

```
