# Plotly gives error with contour plot

**URL:** <https://discourse.julialang.org/t/plotly-gives-error-with-contour-plot/39462>\
**Category:** New to Julia\
**Created:** [May 14, 2020, 11:44am UTC](https://discourse.julialang.org/t/plotly-gives-error-with-contour-plot/39462 "2020-05-14T11:44:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![O\_Julia](https://avatars.discourse-cdn.com/v4/letter/o/3ab097/32.png) [@O\_Julia](https://discourse.julialang.org/u/O_Julia)\
**Post date:** [May 14, 2020, 11:44am UTC](https://discourse.julialang.org/t/plotly-gives-error-with-contour-plot/39462/1 "2020-05-14T11:44:33Z")

</div>

I am using Julia 1.4.1 with juno. I want to draw a filled contour plot. Following codes give me error.

```julia

using Plots

x = -3:0.1:3
y = -3:0.1:3
X = reshape([xi for xi in x for yj in y], length(y), length(x))
Y = reshape([yj for xi in x for yj in y], length(y), length(x))

Z = X + im*Y;
R(z)= @. (1 + z + 1/2*z^2 + 1/6*z^3 + 1/24*z^4);
R3 = abs.(R(Z));

plotly()
levs=[0; 1]
contour(x, y, R3,levels=levs,fill=true) 
#contour(x, y, R3,levels=levs)

```

Error:

```julia
MethodError: no method matching +(::Array{Int64,1}, ::Int64)

Closest candidates are:

+(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:529

+(!Matched::Complex{Bool}, ::Real) at complex.jl:301

+(!Matched::Missing, ::Number) at missing.jl:115

...

plotly_series(::Plots.Plot{Plots.PlotlyBackend}, ::Plots.Series) at plotly.jl:520

plotly_series(::Plots.Plot{Plots.PlotlyBackend}) at plotly.jl:797

plotly_series_json at plotly.jl:803 [inlined]

plotly_html_body(::Plots.Plot{Plots.PlotlyBackend}, ::Nothing) at plotly.jl:838

plotly_html_body at plotly.jl:833 [inlined]

html_body at plotly.jl:808 [inlined]

standalone_html(::Plots.Plot{Plots.PlotlyBackend}; title::String) at web.jl:7

standalone_html(::Plots.Plot{Plots.PlotlyBackend}) at web.jl:7

_show at plotly.jl:874 [inlined]

_showjuno at output.jl:284 [inlined]

showjuno(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::MIME{Symbol("text/html")}, ::Plots.Plot{Plots.PlotlyBackend}) at output.jl:266

show(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::MIME{Symbol("application/prs.juno.plotpane+html")}, ::Plots.Plot{Plots.PlotlyBackend}) at output.jl:221

show(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::String, ::Plots.Plot{Plots.PlotlyBackend}) at multimedia.jl:109

displayinplotpane(::Plots.Plot{Plots.PlotlyBackend}) at showdisplay.jl:51

displayandrender(::Plots.Plot{Plots.PlotlyBackend}) at showdisplay.jl:131

(::Atom.var"#201#205")() at eval.jl:177

#invokelatest#1 at essentials.jl:712 [inlined]

invokelatest at essentials.jl:711 [inlined]

(::Atom.var"#200#204"{String,String})() at eval.jl:176

withpath(::Atom.var"#200#204"{String,String}, ::String) at utils.jl:30

withpath(::Function, ::String) at eval.jl:9

#199 at eval.jl:161 [inlined]

with_logstate(::Atom.var"#199#203"{String,String}, ::Base.CoreLogging.LogState) at logging.jl:398

with_logger at logging.jl:505 [inlined]

#198 at eval.jl:160 [inlined]

hideprompt(::Atom.var"#198#202"{String,String}) at repl.jl:140

macro expansion at dynamic.jl:24 [inlined]

evalall(::String, ::Nothing, ::String) at eval.jl:150

macro expansion at eval.jl:39 [inlined]

(::Atom.var"#172#173")() at task.jl:358

```

If I use a scalar value instead of `levs` say `5` then it works however it does not work with array `levs`. Also, If I use gr() backend `contour(x, y, R3,levels=levs)` works but `contour(x, y, R3,levels=levs,fill=true)` does not work. How can I fix these errors?

---

<div class="post-metadata">

**Author:** ![natgeo-wong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/natgeo-wong/32/10965_2.png) [@natgeo-wong](https://discourse.julialang.org/u/natgeo-wong)\
**Post date:** [May 15, 2020, 8:33am UTC](https://discourse.julialang.org/t/plotly-gives-error-with-contour-plot/39462/2 "2020-05-15T08:33:06Z")

</div>

My guess is that the error comes from this set:

```julia
R(z)= @. (1 + z + 1/2*z^2 + 1/6*z^3 + 1/24*z^4);
R3 = abs.(R(Z));

```

Instead, I would change it to

```julia
R(z) = 1 + z + 1/2*z^2 + 1/6*z^3 + 1/24*z^4
R3 = abs.(R.(Z));

```

This correctly broadcasts the function over the matrix.

---

<div class="post-metadata">

**Author:** ![O\_Julia](https://avatars.discourse-cdn.com/v4/letter/o/3ab097/32.png) [@O\_Julia](https://discourse.julialang.org/u/O_Julia)\
**Post date:** [May 15, 2020, 9:44am UTC](https://discourse.julialang.org/t/plotly-gives-error-with-contour-plot/39462/3 "2020-05-15T09:44:15Z")

</div>

Thank you for your suggestion. But, it does not work. I get same error.

---

<div class="post-metadata">

**Author:** ![josephmarturano](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@josephmarturano](https://discourse.julialang.org/u/josephmarturano)\
**Post date:** [May 15, 2020, 5:23pm UTC](https://discourse.julialang.org/t/plotly-gives-error-with-contour-plot/39462/4 "2020-05-15T17:23:36Z")

</div>

Maybe specifying contour levels is not supported with the plotly backend and Plots.jl? But you can get something working with Plotlyjs.jl directly. If you only want two levels, 0 or 1, you could use the following:

```julia
using PlotlyJS, ORCA

x = -3:0.1:3
y = -3:0.1:3
X = reshape([xi for xi in x for yj in y], length(y), length(x))
Y = reshape([yj for xi in x for yj in y], length(y), length(x))

Z = X + im*Y;
R(z)= @. (1 + z + 1/2*z^2 + 1/6*z^3 + 1/24*z^4);
R3 = abs.(R(Z))

testcontour = Plot(contour(; x=x, y=y, z=R3, autocontour=false, contours=Dict(:start=>0, :end=>1, :size=>1)))
ORCA.savefig(testcontour, "testcontour.png")
ORCA.savefig(testcontour, "testcontour.html")

```

Which yields the following:

 ![testcontour](https://global.discourse-cdn.com/julialang/original/3X/0/7/0790654be6ce4f2f018a472e32369d4ce15b4beb.png)
