I am trying to learn to plot a 2d vector field. I try to follow the example here.
using Plots
plotly()
meshgrid(x, y) = (repeat(x, outer=length(y)), repeat(y, inner=length(x)))
x, y = meshgrid(0.0:0.2:2.0, 0.0:0.2:2.0)
u = cos.(x) .* y
v = sin.(x) .* y # orginal had v = @. sin(x) * y but it looks like that's outdated? I changed it to this
quiver(x, y, quiver=(u, v))
If instead of quiver(x, y, quiver=(u, v)), I try quiver(x,y,u,v) as per the Matplotlib documentation, I get "Couldn’t process recipe args: (Array{Float64,1}, Array{Float64,1}, Array{Float64,1}, Array{Float64,1})
"
Full error
At first I had some ints mixed with floats, but making everything float didn’t help.
I you don’t need to use Plots.jl, this can be easily reproduced with Gaston:
using Gaston
meshgrid(x, y) = (repeat(x, outer=length(y)), repeat(y, inner=length(x)))
x, y = meshgrid(0.0:0.2:2.0, 0.0:0.2:2.0)
u = 0.15 * cos.(x) .* y
v = 0.15 * sin.(x) .* y
plot(x, y, supp = [u v], w = :vectors)
With a couple caveats (only 1 matters), that worked thanks!
It didn’t work in Jupyterlab. It only worked in Jupyter notebook.
it just gives a little image icon below the cell but no output.
I found a thread about a related python problem here. People were saying you need to use %matplotlib inline . Not sure if that’s applicable to julia or what that means.
This example works fine with Plots with the GR backend.
Just remove plotly().
Note that matplotlib has nothing to do with Plots.jl, so it’s not expected that the syntax is necessarily the same. (Although the syntax in Plots.jl could be said to be unnecessarily complicated.)
Also, I’m not sure what you mean by a “2x2” vector field.
EDIT: It may be a good idea to normalise the vectors you’re plotting to all have the same length.