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

Cannot convert Float64 to series data for plotting in 0.27.0 #2249

Closed
homocomputeris opened this issue Nov 12, 2019 · 6 comments
Closed

Cannot convert Float64 to series data for plotting in 0.27.0 #2249

homocomputeris opened this issue Nov 12, 2019 · 6 comments

Comments

@homocomputeris
Copy link

using Plots
ints = collect(1:3)
floats = float(ints)
plot(ints...)
plot(floats...)

gives

Cannot convert Float64 to series data for plotting
Stacktrace:
 [1] prepareSeriesData(::Float64) at /home/user/.julia/packages/Plots/Iuc9S/src/series.jl:15
 [2] convertToAnyVector(::Float64, ::Dict{Symbol,Any}) at /home/user/.julia/packages/Plots/Iuc9S/src/series.jl:26
 [3] macro expansion at /home/user/.julia/packages/Plots/Iuc9S/src/series.jl:129 [inlined]
 [4] apply_recipe(::Dict{Symbol,Any}, ::Type{Plots.SliceIt}, ::Float64, ::Float64, ::Float64) at /home/user/.julia/packages/RecipesBase/zBoFG/src/RecipesBase.jl:275
 [5] _process_userrecipes(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Float64,Float64,Float64}) at /home/user/.julia/packages/Plots/Iuc9S/src/pipeline.jl:83
 [6] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Float64,Float64,Float64}) at /home/user/.julia/packages/Plots/Iuc9S/src/plot.jl:178
 [7] #plot#137(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(plot), ::Float64, ::Vararg{Float64,N} where N) at /home/user/.julia/packages/Plots/Iuc9S/src/plot.jl:57
 [8] plot(::Float64, ::Float64, ::Vararg{Float64,N} where N) at /home/user/.julia/packages/Plots/Iuc9S/src/plot.jl:51
 [9] top-level scope at In[56]:5
  Status `~/.julia/environments/v1.2/Project.toml`
  [682c06a0] JSON v0.21.0
  [91a5bcdd] Plots v0.27.0
@yha
Copy link
Member

yha commented Nov 13, 2019

What is the expected behavior? Perhaps you mean plot(floats), without the ellipsis?
I'm surprised plot(ints...) doesn't error, but I think its behavior is also a bit surprising.

@homocomputeris
Copy link
Author

homocomputeris commented Nov 13, 2019

If I want to plot a point in 3D space, what command am I supposed to use? plot(ints...) does what I want.
Where are the docs for plot? ?plot is useless.

julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.2.0 (2019-08-20)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |

julia> using Plots

julia> x = float(collect(1:3))
3-element Array{Float64,1}:
 1.0
 2.0
 3.0

julia> plot(x)
# plot of a line in 2D appears

julia> plot(x...)
ERROR: Cannot convert Float64 to series data for plotting
Stacktrace:
 [1] prepareSeriesData(::Float64) at /home/nik/.julia/packages/Plots/Iuc9S/src/series.jl:15
 [2] convertToAnyVector(::Float64, ::Dict{Symbol,Any}) at /home/nik/.julia/packages/Plots/Iuc9S/src/series.jl:26
 [3] macro expansion at /home/nik/.julia/packages/Plots/Iuc9S/src/series.jl:129 [inlined]
 [4] apply_recipe(::Dict{Symbol,Any}, ::Type{Plots.SliceIt}, ::Float64, ::Float64, ::Float64) at /home/nik/.julia/packages/RecipesBase/zBoFG/src/RecipesBase.jl:275
 [5] _process_userrecipes(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Float64,Float64,Float64}) at /home/nik/.julia/packages/Plots/Iuc9S/src/pipeline.jl:83
 [6] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Float64,Float64,Float64}) at /home/nik/.julia/packages/Plots/Iuc9S/src/plot.jl:178
 [7] #plot#137(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(plot), ::Float64, ::Vararg{Float64,N} where N) at /home/nik/.julia/packages/Plots/Iuc9S/src/plot.jl:57
 [8] plot(::Float64, ::Float64, ::Vararg{Float64,N} where N) at /home/nik/.julia/packages/Plots/Iuc9S/src/plot.jl:51
 [9] top-level scope at REPL[4]:1

julia> plot3d(x)
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: MethodError: no method matching length(::Nothing)
Closest candidates are:
  length(::Core.SimpleVector) at essentials.jl:597
  length(::Base.MethodList) at reflection.jl:819
  length(::Core.MethodTable) at reflection.jl:893
  ...
Stacktrace:
 [1] map(::typeof(length), ::Tuple{UnitRange{Int64},Array{Float64,1},Nothing}) at ./tuple.jl:141
 [2] iter_segments(::UnitRange{Int64}, ::Array{Float64,1}, ::Vararg{Any,N} where N) at /home/nik/.julia/packages/Plots/Iuc9S/src/utils.jl:190
 [3] iter_segments(::Plots.Series) at /home/nik/.julia/packages/Plots/Iuc9S/src/utils.jl:207
 [4] gr_display(::Plots.Subplot{Plots.GRBackend}, ::Measures.Length{:mm,Float64}, ::Measures.Length{:mm,Float64}, ::Array{Float64,1}) at /home/nik/.julia/packages/Plots/Iuc9S/src/backends/gr.jl:1363
 [5] gr_display(::Plots.Plot{Plots.GRBackend}, ::String) at /home/nik/.julia/packages/Plots/Iuc9S/src/backends/gr.jl:685
 [6] gr_display at /home/nik/.julia/packages/Plots/Iuc9S/src/backends/gr.jl:643 [inlined]
 [7] _display(::Plots.Plot{Plots.GRBackend}) at /home/nik/.julia/packages/Plots/Iuc9S/src/backends/gr.jl:1629
 [8] display(::Plots.PlotsDisplay, ::Plots.Plot{Plots.GRBackend}) at /home/nik/.julia/packages/Plots/Iuc9S/src/output.jl:144
 [9] #invokelatest#1 at ./essentials.jl:790 [inlined]
 [10] invokelatest at ./essentials.jl:789 [inlined]
 [11] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at /build/julia/src/julia-1.2.0/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:156
 [12] (::getfield(REPL, Symbol("#do_respond#38")){Bool,getfield(REPL, Symbol("##48#57")){REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /build/julia/src/julia-1.2.0/usr/share/julia/stdlib/v1.2/REPL/src/REPL.jl:718

julia> plot3d(x...)
ERROR: Cannot convert Float64 to series data for plotting
Stacktrace:
 [1] prepareSeriesData(::Float64) at /home/nik/.julia/packages/Plots/Iuc9S/src/series.jl:15
 [2] convertToAnyVector(::Float64, ::Dict{Symbol,Any}) at /home/nik/.julia/packages/Plots/Iuc9S/src/series.jl:26
 [3] macro expansion at /home/nik/.julia/packages/Plots/Iuc9S/src/series.jl:129 [inlined]
 [4] apply_recipe(::Dict{Symbol,Any}, ::Type{Plots.SliceIt}, ::Float64, ::Float64, ::Float64) at /home/nik/.julia/packages/RecipesBase/zBoFG/src/RecipesBase.jl:275
 [5] _process_userrecipes(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Float64,Float64,Float64}) at /home/nik/.julia/packages/Plots/Iuc9S/src/pipeline.jl:83
 [6] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Float64,Float64,Float64}) at /home/nik/.julia/packages/Plots/Iuc9S/src/plot.jl:178
 [7] #plot#137(::Base.Iterators.Pairs{Symbol,Symbol,Tuple{Symbol},NamedTuple{(:seriestype,),Tuple{Symbol}}}, ::typeof(plot), ::Float64, ::Vararg{Float64,N} where N) at /home/nik/.julia/packages/Plots/Iuc9S/src/plot.jl:57
 [8] (::getfield(RecipesBase, Symbol("#kw##plot")))(::NamedTuple{(:seriestype,),Tuple{Symbol}}, ::typeof(plot), ::Float64, ::Float64, ::Vararg{Float64,N} where N) at ./none:0
 [9] #plot3d#442(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(plot3d), ::Float64, ::Vararg{Float64,N} where N) at /home/nik/.julia/packages/Plots/Iuc9S/src/shorthands.jl:387
 [10] plot3d(::Float64, ::Vararg{Float64,N} where N) at /home/nik/.julia/packages/Plots/Iuc9S/src/shorthands.jl:387
 [11] top-level scope at REPL[6]:1

@yha
Copy link
Member

yha commented Nov 13, 2019

To plot a single point, you still need to pass a vector for each of x,y,z.
You should also use scatter, or specify markers, since by default plot only plots lines between points and won't show anything for a single point. So either of the following:

scatter([1],[2],[3])
plot([1],[2],[3], marker=:circle)

You can also pass points as tuple of coordinates, like plot([(1,2,3)]). So if you already have the coordinates in a vector as in your example,

x = [1,2,3]
scatter([tuple(x...)])

@daschw daschw closed this as completed Nov 19, 2019
@homocomputeris
Copy link
Author

In the end, should

plot(ints...)
plot(floats...)

have the same of different behavior or not? Should both raise an error?

@yha
Copy link
Member

yha commented Nov 19, 2019

plot(n), with a single integer n, creates n empty series. This behavior is deliberate and documented.
plot(ints...) apparently does the same thing as plot(maximum(ints)), which is probably a bug.
plot(floats...) should and does error. Maybe it can be changed to mean plotting a single point, but this conflicts with the current meaning of plot(n) (see the discussion in #2129).

@homocomputeris
Copy link
Author

Thanks for the explanation.

plot(n), with a single integer n, creates n empty series. This behavior is deliberate and documented.

I'd say this semantics is rather counterintuitive. If plot(series1, series2) is a valid plot, I'd expect that plot(int) is a plot of a point versus an axis or nothing at all, but not an plot with n empty series.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants