Search code examples
juliajulia-plots

Arrays have incorrect length or dimension. Contour plot in Julia


I am trying to make a simple contour plot.

using Plots

xi = -10:10
zi = 0:-1:-10

X = xi'.*ones(size(zi))
Z = zi .*ones(size(xi))'

plot(contour(X, Z, X, fill = true))

Which returns Arrays have incorrect length or dimension. and an empty figure.

Any idea on what does that means?

size(X),size(Z) returns ((11, 21), (11, 21))


Solution

  • I have been confused by this before. In your call to contour the first two arguments need to be one dimensional arrays, but the third argument should be 2D, i.e. if you change your code to:

    contour(xi,reverse(zi),X,fill=true)
    

    It will run (just tested on my system, see attached pic). I use reverse(zi) because the points for the contour have to be sorted in ascending order as well.

    enter image description here