Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Plotly backend does not support passing arrays as levels in contour plot #3356

Open
melonedo opened this issue Mar 18, 2021 · 0 comments

Comments

@melonedo
Copy link

Details

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) x
pyplot
plotly x
plotlyjs x
pgfplotsx
inspectdr

Versions

Plots.jl version: v1.10.6
Backend version (]st -m): [f0f68f2c] PlotlyJS v0.14.1
Output of versioninfo():

Julia Version 1.5.4
Commit 69fcb5745b (2021-03-11 19:13 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)

MWE:

using Plots
plotlyjs()
contour(0:1:10, 0:1:10, (x,y)->x*y, levels=[1,2,3])

Result:

julia> contour(0:1:10, 0:1:10, (x,y)->x*y, levels=[1,2,3])
Error showing value of type Plots.Plot{Plots.PlotlyJSBackend}:
ERROR: MethodError: no method matching +(::Array{Int64,1}, ::Int64)
For element-wise addition, use broadcasting with dot syntax: array .+ scalar
Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...) at operators.jl:538
  +(::Missing, ::Number) at missing.jl:115
  +(::Base.CoreLogging.LogLevel, ::Integer) at logging.jl:116
  ...
Stacktrace:
 [1] plotly_series(::Plots.Plot{Plots.PlotlyJSBackend}, ::Plots.Series) at C:\Users\melonedo\.julia\packages\Plots\SjqWU\src\backends\plotly.jl:570
 [2] plotly_series(::Plots.Plot{Plots.PlotlyJSBackend}) at C:\Users\melonedo\.julia\packages\Plots\SjqWU\src\backends\plotly.jl:873
 [3] plotlyjs_syncplot(::Plots.Plot{Plots.PlotlyJSBackend}) at C:\Users\melonedo\.julia\packages\Plots\SjqWU\src\backends\plotlyjs.jl:9
 [4] _display(::Plots.Plot{Plots.PlotlyJSBackend}) at C:\Users\melonedo\.julia\packages\Plots\SjqWU\src\backends\plotlyjs.jl:39
 [5] display(::Plots.PlotsDisplay, ::Plots.Plot{Plots.PlotlyJSBackend}) at C:\Users\melonedo\.julia\packages\Plots\SjqWU\src\output.jl:150
 [6] display(::Any) at .\multimedia.jl:328
 [7] #invokelatest#1 at .\essentials.jl:710 [inlined]
 [8] invokelatest at .\essentials.jl:709 [inlined]
 [9] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\REPL\src\REPL.jl:238
 [10] print_response(::REPL.AbstractREPL, ::Any, ::Bool, ::Bool) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\REPL\src\REPL.jl:223
 [11] (::REPL.var"#do_respond#54"{Bool,Bool,REPL.var"#64#73"{REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\REPL\src\REPL.jl:822
 [12] #invokelatest#1 at .\essentials.jl:710 [inlined]
 [13] invokelatest at .\essentials.jl:709 [inlined]
 [14] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\REPL\src\LineEdit.jl:2355
 [15] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\REPL\src\REPL.jl:1144
 [16] (::REPL.var"#38#42"{REPL.LineEditREPL,REPL.REPLBackendRef})() at .\task.jl:356

Suspicious line:

plotattributes_out[:ncontours] = series[:levels] + 2

@melonedo melonedo added the bug label Mar 18, 2021
anowacki added a commit to anowacki/Plots.jl that referenced this issue Aug 19, 2021
Plotly does not support arbitrary contour values, but can plot
specific contours if they are an equally-spaced range.  This
commit implements the plotting of contours if the `levels`
keyword argument is passed an `AbstractRange`, or if a set
of arbitrary values are passed.  In the latter case, however,
since this is not supported by Plotly, a range based on the
first and last values of the collection passed in is created
and used to define the contours.  A warning is then issued to
the user.

Otherwise, any other types are assumed to be number-like and
adjusted as previously.  Note that Plotly does not guarantee
the exact number of contours will be used.

This partly addresses JuliaPlots#3356.

See plotly/plotly.js#4503 (Plotly issue
tracking the ability to set arbitrary contours).
anowacki added a commit to anowacki/Plots.jl that referenced this issue Aug 20, 2021
Plotly does not support arbitrary contour values, but can plot
specific contours if they are an equally-spaced range.  This
commit implements the plotting of contours if the `levels`
keyword argument is passed an `AbstractRange`, or if a set
of arbitrary values are passed.  In the latter case, however,
since this is not supported by Plotly, a range based on the
first and last values of the collection passed in is created
and used to define the contours.  A warning is then issued to
the user.

Otherwise, any other types are assumed to be number-like and
adjusted as previously.  Note that Plotly does not guarantee
the exact number of contours will be used.

This partly addresses JuliaPlots#3356.

See plotly/plotly.js#4503 (Plotly issue
tracking the ability to set arbitrary contours).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants