Problems with level curves

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

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
(I want only on level 2).
How can I fix this?
On my computer, does not work the package Pyplot.

The syntax is

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.

1 Like

Thank you for the response.
However, when I run

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
Could you like to help me please?

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> 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)

2 Likes

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

image

When I add a comma, the error appears:

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

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.

1 Like

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

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:

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!

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

1 Like