JuliaPlots/Plots.jl

DimensionError: K and NaN are not dimensionally compatible.

Open

#5035 aperta il 28 nov 2024

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)Julia (381 fork)batch import
good first issue

Metriche repository

Star
 (1943 star)
Metriche merge PR
 (Merge medio 13g 6h) (2 PR mergiate in 30 g)

Descrizione

could be related to https://github.com/JuliaPlots/Plots.jl/issues/4750

Details

Errors on trying to plot Vector of Vectors, wherein data are Unitful, but some are missing.

The error message mentions NaNs, however there were no NaNs in the data.

MWE

using DataFrames, Plots, Unitful
gr() # or other backend

y1 = fill(32.0u"°C", 5)
y2 = vcat(fill(missing, 2), fill(22.0u"°C", 3))
df = DataFrame((; y1, y2))
tcl = eachcol(df) |> collect
m2 = Matrix(df)

p0 = plot([y1, y2]); display(p0); # OK
p1 = plot(m2); display(p1); # OK.  As my data coming from a DataFrame, this is a usable alternative for me.
p2 = plot([tcl[1], tcl[2]]); display(p2); # OK, but similar code errored in my actual use case
p2a = plot(tcl[1]); plot!(tcl[2]); display(p2a); # OK, but similar code errored in my actual use case
p3 = plot(tcl); # errors

Error stack

ERROR: DimensionError: K and NaN are not dimensionally compatible.
Stacktrace:
  [1] convert(::Type{Quantity{Float64, 𝚯, Unitful.FreeUnits{(K,), 𝚯, nothing}}}, x::Float64)
    @ Unitful ~/.julia/packages/Unitful/GYzMo/src/conversion.jl:106
  [2] setindex!(A::Vector{Quantity{Float64, 𝚯, Unitful.FreeUnits{(K,), 𝚯, nothing}}}, x::Float64, i::Int64)
    @ Base ./array.jl:976
  [3] macro expansion
    @ ./broadcast.jl:968 [inlined]
  [4] macro expansion
    @ ./simdloop.jl:77 [inlined]
  [5] copyto!
    @ ./broadcast.jl:967 [inlined]
  [6] copyto!
    @ ./broadcast.jl:920 [inlined]
  [7] materialize!
    @ ./broadcast.jl:878 [inlined]
  [8] materialize!
    @ ./broadcast.jl:875 [inlined]
  [9] broadcast!(f::RecipesPipeline.var"#13#14", dest::Vector{Quantity{…}}, As::Vector{Union{…}})
    @ Base.Broadcast ./broadcast.jl:844
 [10] _prepare_series_data
    @ ~/.julia/packages/RecipesPipeline/BGM3l/src/series.jl:20 [inlined]
 [11] _series_data_vector
    @ ~/.julia/packages/RecipesPipeline/BGM3l/src/series.jl:42 [inlined]
 [12] (::RecipesPipeline.var"#21#24"{Dict{Symbol, Any}})(vi::Vector{Union{Missing, Quantity{…}}})
    @ RecipesPipeline ./none:0
 [13] iterate(g::Base.Generator{Vector{AbstractVector}, RecipesPipeline.var"#21#24"{Dict{Symbol, Any}}}, s::Int64)
    @ Base ./generator.jl:48
 [14] _series_data_vector(v::Vector{AbstractVector}, plotattributes::Dict{Symbol, Any})
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/series.jl:51
 [15] macro expansion
    @ ~/.julia/packages/RecipesPipeline/BGM3l/src/series.jl:129 [inlined]
 [16] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, ::Type{RecipesPipeline.SliceIt}, x::Any, y::Any, z::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:300
 [17] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/user_recipe.jl:38
 [18] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/RecipesPipeline.jl:72
 [19] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/Ec1L1/src/plot.jl:223
 [20] plot(args::Any; kw...)
    @ Plots ~/.julia/packages/Plots/Ec1L1/src/plot.jl:102
 [21] plot(args::Any)
    @ Plots ~/.julia/packages/Plots/Ec1L1/src/plot.jl:93
 [22] top-level scope
    @ ~/Julia/PlotsBugReport/test_gr.jl:11
Some type information was truncated. Use `show(err)` to see complete types.

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) x
pythonplot x
plotlyjs x
pgfplotsx x
unicodeplots x
inspectdr x
gaston x

Versions

Plots.jl version: v1.40.9

Backend version (]st -m <backend(s)>): GR v0.73.8, PGFPlotsX v1.6.2, PlotlyJS v0.18.15

Unitful v1.21.0 DataFrames v1.7.0

Output of versioninfo():

Julia Version 1.11.1
Commit 8f5b7ca12ad (2024-10-16 10:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 6 default, 0 interactive, 3 GC (on 4 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 6

Guida contributor