Streamplot from numerical data #3157
Replies: 5 comments 8 replies
-
@jkrumbiegel, anything on this? |
Beta Was this translation helpful? Give feedback.
-
I think we currently only take a function because you need to be able to evaluate it continuously. But we could (or you could) use an interpolation over the matrix as the function, which should then result in what matplotlib does. |
Beta Was this translation helpful? Give feedback.
-
Okay, I will give it a shot. |
Beta Was this translation helpful? Give feedback.
-
Okay, this simple snippet works. using CairoMakie, Interpolations
function splot(u, v)
nx, ny = size(u)
x, y = 1:nx, 1:ny
intu, intv = linear_interpolation((x,y), u), linear_interpolation((x,y), v)
f(x) = Point2f(intu(x...), intv(x...))
return streamplot(f, x, y, colormap=:magma)
end
# Streamplot example function
struct FitzhughNagumo{T}
ϵ::T
s::T
γ::T
β::T
end
P = FitzhughNagumo(0.1, 0.0, 1.5, 0.8)
x = -1.5:0.1:1.5
nx = length(x)
u, v = zeros(nx, nx), zeros(nx, nx)
for (j, xj) in enumerate(x)
for (i, xi) in enumerate(x)
u[i, j], v[i, j] = (xi-xj-xi^3+P.s)/P.ϵ, P.γ*xi-xj + P.β
end
end
fig, ax, pl = splot(u, v) Can we extend the recipe to support plotting numerical data? If yes, I can improve upon it and open a pull request. Any suggestions on improvements are also welcome. |
Beta Was this translation helpful? Give feedback.
-
About your arrows issue, I do not know, perhaps you have a modified Makie theme or some other custom setting, try updating Makie, running the example code in a clean repl/notebook. About plotting 1D arrays, Interpolation over a D-tuple requires D dimensional data. For example this snippet using CairoMakie, Interpolations
function splot(x, y, u, v)
intu, intv = linear_interpolation((x,y), u), linear_interpolation((x,y), v)
f(x) = Point2f(intu(x...), intv(x...))
return streamplot(f, x, y, colormap=:magma)
end
x = 0:0.2:2π
y = 0:0.2:2π
u = @. sin(x) * cos(y')
v = @. cos(x) * sin(y')
splot(x, y, u, v) However
Note the function signature So, I think you need to reshape your |
Beta Was this translation helpful? Give feedback.
-
The documentation says that we can create a streamplot for a function that returns
dx,dy
for a givenx,y
. Say I have numerical values of the coordinates and the velocities, how can I create a streamplot? Essentially, I want a plotting recipe equivalent to matplotlib streamplot.Beta Was this translation helpful? Give feedback.
All reactions