# Problems with level curves

**URL:** <https://discourse.julialang.org/t/problems-with-level-curves/51488>\
**Category:** New to Julia\
**Created:** [December 9, 2020, 1:39am UTC](https://discourse.julialang.org/t/problems-with-level-curves/51488 "2020-12-09T01:39:04Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [December 9, 2020, 1:39am UTC](https://discourse.julialang.org/t/problems-with-level-curves/51488/1 "2020-12-09T01:39:04Z")

</div>

Dear all  
I have the following code to plot the level curves:

```julia
using Plots
plotly()
import Contour: contours, levels, level, lines, coordinates
f(x,y) = y^2 + x^2
xs = ys = range(-5, stop=5, length=100)
contour(xs, ys, f,level=2)

```

but several level curves are presented. See the figure below.

![level](https://global.discourse-cdn.com/julialang/original/3X/7/8/7843519387ce0396343e0833d46d09aff797b073.png)  
(I want only on level 2).  
How can I fix this?  
On my computer, does not work the package Pyplot.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [December 9, 2020, 4:23am UTC](https://discourse.julialang.org/t/problems-with-level-curves/51488/2 "2020-12-09T04:23:09Z")

</div>

The syntax is

```julia
contour(xs, ys, f, levels=[2], ratio=1)

```

If you want several levels, use  
`levels = [2.1, 2.2]`

This definitely works with GR; last time I tried with Plotly I’m not sure that it did.

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [December 9, 2020, 2:27pm UTC](https://discourse.julialang.org/t/problems-with-level-curves/51488/3 "2020-12-09T14:27:24Z")

</div>

Thank you for the response.  
However, when I run

```julia
using Plots
import Contour: contours, levels, level, lines, coordinates
xs = range(-5, stop=5, length=100)
ys = range(-5, stop=5, length=100)
f(x,y) = x^2+y^2#0.5*(0.8*x^2+2*x*y+2*y^2) - x - 2*y
contour(xs, ys, f,levels=[2 3],ratio=1)

```

I don’t have two levels curves (only one at a wrong level). See below.  
 ![level](https://global.discourse-cdn.com/julialang/original/3X/0/1/013a28a2d0c51ecf87ec1a9f8b83be3b51a35d92.png)  
Could you like to help me please?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 9, 2020, 2:37pm UTC](https://discourse.julialang.org/t/problems-with-level-curves/51488/4 "2020-12-09T14:37:00Z")

</div>

I think you only have to add a `,` between the levels.

Also importing explicitly those packages does not seem necessary, at least for your mwe:

```julia
julia> using Plots

julia> xs = range(-5, stop=5, length=100)
-5.0:0.10101010101010101:5.0

julia> ys = range(-5, stop=5, length=100)
-5.0:0.10101010101010101:5.0

julia> f(x,y) = x^2+y^2#0.5*(0.8*x^2+2*x*y+2*y^2) - x - 2*y
f (generic function with 1 method)

julia> contour(xs, ys, f,levels=[1, 2, 3, 10, 15, 30],ratio=1)

```

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [December 9, 2020, 2:40pm UTC](https://discourse.julialang.org/t/problems-with-level-curves/51488/5 "2020-12-09T14:40:33Z")

</div>

> [@lmiq](#):
>
> `contour(xs, ys, f,levels=[1, 2, 3, 10, 15, 30],ratio=1)`

In you computer works?  
Could you show me the figure?  
I add “,” but yet not work.  
My gr() has a problem.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 9, 2020, 2:41pm UTC](https://discourse.julialang.org/t/problems-with-level-curves/51488/6 "2020-12-09T14:41:38Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/5/c/5ce3b1a1ace92f68b576df85a9e4ea3d149f788b.png)

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [December 9, 2020, 2:42pm UTC](https://discourse.julialang.org/t/problems-with-level-curves/51488/7 "2020-12-09T14:42:51Z")

</div>

When I add a comma, the error appears:

```julia
MethodError: no method matching +(::Array{Float64,1}, ::Int64)
For element-wise addition, use broadcasting with dot syntax: array .+ scalar
Closest candidates are:
  +(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:538
  +(!Matched::Missing, ::Number) at missing.jl:115
  +(!Matched::Base.CoreLogging.LogLevel, ::Integer) at logging.jl:116
  ...
plotly_series(::Plots.Plot{Plots.PlotlyBackend}, ::Plots.Series) at plotly.jl:559
plotly_series(::Plots.Plot{Plots.PlotlyBackend}) at plotly.jl:862
plotly_series_json at plotly.jl:868 [inlined]
plotly_html_body(::Plots.Plot{Plots.PlotlyBackend}, ::Nothing) at plotly.jl:908
plotly_html_body at plotly.jl:903 [inlined]
html_body at plotly.jl:873 [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:944 [inlined]
_showjuno at output.jl:273 [inlined]
showjuno(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::MIME{Symbol("text/html")}, ::Plots.Plot{Plots.PlotlyBackend}) at output.jl:257
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:111
displayinplotpane(::Plots.Plot{Plots.PlotlyBackend}) at showdisplay.jl:51
displayandrender(::Plots.Plot{Plots.PlotlyBackend}) at showdisplay.jl:131
(::Atom.var"#204#209"{String})() at eval.jl:136
#invokelatest#1 at essentials.jl:710 [inlined]
invokelatest at essentials.jl:709 [inlined]
macro expansion at dynamic.jl:24 [inlined]
eval(::String, ::Int64, ::String, ::String, ::Bool) at eval.jl:113
invokelatest(::Any, ::Any, ::Vararg{Any,N} where N; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at essentials.jl:710
invokelatest(::Any, ::Any, ::Vararg{Any,N} where N) at essentials.jl:709
macro expansion at eval.jl:41 [inlined]
(::Atom.var"#184#185")() at task.jl:356

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 9, 2020, 2:44pm UTC](https://discourse.julialang.org/t/problems-with-level-curves/51488/8 "2020-12-09T14:44:44Z")

</div>

Seems that you are using the `Plotly` backend there for some reason.

Do you see the problem after restarting Julia and copying exactly the same commands I have provided there?

If so, maybe `GR` is not installed for some strange reason, and Plots is falling back to `Plotly`.

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [December 9, 2020, 2:50pm UTC](https://discourse.julialang.org/t/problems-with-level-curves/51488/9 "2020-12-09T14:50:49Z")

</div>

Thank you for teh response again.  
I have re-started.  
When I run exactly your commands

```julia
using Plots
xs = range(-5, stop=5, length=100)
ys = range(-5, stop=5, length=100)
f(x,y) = x^2+y^2
contour(xs, ys, f,levels=[1, 2, 3, 10, 15, 30],ratio=1)

```

the Julia restart misteriously and appears the errors message:

```julia
GKS: file open error (C:\Users\Usuário\.julia\packages\GR\BwGt2\src\..\deps\gr\FONTS\GKSFONT.DAT)
open: No such file or directory
GKS: svgplugin.dll: can't load library, error 126 (0x7e)
GKS: could not open font file: C:\Users\Usuário\.julia\packages\GR\BwGt2\src\..\deps\gr\FONTS\CMUSerif-Math.ttf
GKS: could not open font file: C:\Users\Usuário\.julia\packages\GR\BwGt2\src\..\deps\gr\FONTS\DejaVuSans.ttf
GKS: glyph missing from current font: 73
GKS: could not load glyph: 0

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x6c2f5698 -- gks_ft_get_kerning at C:\Users\Usußrio\.julia\packages\GR\BwGt2\deps\gr\bin\libGKS.dll (unknown line)
in expression starting at none:0
gks_ft_get_kerning at C:\Users\Usußrio\.julia\packages\GR\BwGt2\deps\gr\bin\libGKS.dll (unknown line) 
gks_ft_get_kerning at C:\Users\Usußrio\.julia\packages\GR\BwGt2\deps\gr\bin\libGKS.dll (unknown line) 
gks_ft_get_kerning at C:\Users\Usußrio\.julia\packages\GR\BwGt2\deps\gr\bin\libGKS.dll (unknown line) 
gks_inq_text_extent at C:\Users\Usußrio\.julia\packages\GR\BwGt2\deps\gr\bin\libGKS.dll (unknown line)
gr_inqtext at C:\Users\Usußrio\.julia\packages\GR\BwGt2\deps\gr\bin\libGR.dll (unknown line)
inqtext at C:\Users\Usu├írio\.julia\packages\GR\BwGt2\src\GR.jl:650 [inlined]
gr_inqtext at C:\Users\Usu├írio\.julia\packages\Plots\hyS17\src\backends\gr.jl:193
gr_text_size at C:\Users\Usu├írio\.julia\packages\Plots\hyS17\src\backends\gr.jl:636
gr_get_ticks_size at C:\Users\Usu├írio\.julia\packages\Plots\hyS17\src\backends\gr.jl:651
unknown function (ip: 0000000047235FE0)
_update_min_padding! at C:\Users\Usu├írio\.julia\packages\Plots\hyS17\src\backends\gr.jl:800
iterate at .\generator.jl:47 [inlined]
_collect at .\array.jl:699
collect_similar at .\array.jl:628
unknown function (ip: 00000000472198F4)
map at .\abstractarray.jl:2162
_update_min_padding! at C:\Users\Usu├írio\.julia\packages\Plots\hyS17\src\layouts.jl:310
prepare_output at C:\Users\Usu├írio\.julia\packages\Plots\hyS17\src\plot.jl:184
showjuno at C:\Users\Usu├írio\.julia\packages\Plots\hyS17\src\output.jl:255
show at C:\Users\Usu├írio\.julia\packages\Plots\hyS17\src\output.jl:212
unknown function (ip: 0000000047218DAF)
show at .\multimedia.jl:111
displayinplotpane at C:\Users\Usu├írio\.julia\packages\Atom\27HB0\src\display\showdisplay.jl:67       
displayandrender at C:\Users\Usu├írio\.julia\packages\Atom\27HB0\src\display\showdisplay.jl:131       
#204 at C:\Users\Usu├írio\.julia\packages\Atom\27HB0\src\eval.jl:136
unknown function (ip: 0000000034A77203)
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1690 [inlined]
do_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:655
jl_f__apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:669 [inlined]
jl_f__apply_latest at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:705   
#invokelatest#1 at .\essentials.jl:710 [inlined]
invokelatest at .\essentials.jl:709 [inlined]
macro expansion at C:\Users\Usu├írio\.julia\packages\Media\ItEPc\src\dynamic.jl:24 [inlined]
eval at C:\Users\Usu├írio\.julia\packages\Atom\27HB0\src\eval.jl:113
unknown function (ip: 0000000034A866F3)
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1690 [inlined]
do_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:655
jl_f__apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:669 [inlined]
jl_f__apply_latest at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:705
#invokelatest#1 at .\essentials.jl:710
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1690 [inlined]
do_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:655
invokelatest at .\essentials.jl:709
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1690 [inlined]
do_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:655
macro expansion at C:\Users\Usu├írio\.julia\packages\Atom\27HB0\src\eval.jl:41 [inlined]
#184 at .\task.jl:356
unknown function (ip: 000000001E01F353)
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1690 [inlined]
start_task at /cygdrive/d/buildbot/worker/package_win64/build/src\task.c:707
Allocations: 77141904 (Pool: 77121152; Big: 20752); GC: 71

```

Other graphics works very well. Only level curves fail.  
Could you help me please? Thanks!

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 9, 2020, 3:30pm UTC](https://discourse.julialang.org/t/problems-with-level-curves/51488/10 "2020-12-09T15:30:13Z")

</div>

There is something broken in your installation. The only thing I can suggest is to remove completely Plots and GR and install them again.
