AlgebraOfGraphics.jl icon indicating copy to clipboard operation
AlgebraOfGraphics.jl copied to clipboard

`density(; datalimits)` expects `datalimits` to be a 1-tuple of a 2-tuple instead of just a 2-tuple

Open rben01 opened this issue 1 year ago • 0 comments

Bug description

density is documented as expecting datalimits to be a 2-tuple, e.g., density(datalimits=(0,10)). However, when you go to plot the data with draw(plt), that leads to the error ERROR: BoundsError: attempt to access Int64 at index [2]. The way to get density to work is to actually wrap that 2-tuple in a 1-tuple: density(datalimits=((0,10),)).

Might be related to #472?

Steps to reproduce

using Random
using AlgebraOfGraphics
using AlgebraOfGraphics: density
using CairoMakie

CairoMakie.activate!()

df = (; x=randn(5000), y=randn(5000))
plt = data(df) * mapping(:x) * density(; datalimits=(-2.5, 2.5))
draw(plt)

The solution is to replace (-2.5, 2.5) with ((-2.5, 2.5),)

Error reporting

ERROR: BoundsError: attempt to access Float64 at index [2]
Stacktrace:
  [1] indexed_iterate(I::Float64, i::Int64, state::Nothing)
    @ Base ./tuple.jl:101
  [2] (::AlgebraOfGraphics.var"#195#196"{Int64})(::Float64)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/transformations/density.jl:21
  [3] map
    @ ./tuple.jl:292 [inlined]
  [4] _density(vs::Tuple{Vector{Float64}}; datalimits::Tuple{Float64, Float64}, npoints::Int64, kwargs::@Kwargs{})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/transformations/density.jl:20
  [5] (::AlgebraOfGraphics.var"#197#198"{@NamedTuple{…}})(p::Vector{Vector{…}}, n::Dictionaries.Dictionary{Symbol, Any})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/transformations/density.jl:31
  [6] (::AlgebraOfGraphics.var"#79#80"{AlgebraOfGraphics.var"#197#198"{@NamedTuple{…}}, ProcessedLayer})(c::CartesianIndex{1})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/algebra/layer.jl:100
  [7] iterate
    @ ./generator.jl:47 [inlined]
  [8] _collect(c::CartesianIndices{…}, itr::Base.Generator{…}, ::Base.EltypeUnknown, isz::Base.HasShape{…})
    @ Base ./array.jl:854
  [9] collect_similar(cont::CartesianIndices{…}, itr::Base.Generator{…})
    @ Base ./array.jl:763
 [10] map(f::Function, A::CartesianIndices{1, Tuple{Base.OneTo{Int64}}})
    @ Base ./abstractarray.jl:3285
 [11] map(f::AlgebraOfGraphics.var"#197#198"{@NamedTuple{…}}, processedlayer::ProcessedLayer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/algebra/layer.jl:99
 [12] (::AlgebraOfGraphics.DensityAnalysis{Tuple{…}, MakieCore.Automatic, MakieCore.Automatic})(input::ProcessedLayer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/transformations/density.jl:30
 [13] process(layer::Layer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/algebra/processing.jl:102
 [14] iterate
    @ ./generator.jl:47 [inlined]
 [15] collect(itr::Base.Generator{Layers, typeof(AlgebraOfGraphics.process)})
    @ Base ./array.jl:834
 [16] map
    @ ./abstractarray.jl:3313 [inlined]
 [17] ProcessedLayers(a::Layer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/algebra/layers.jl:41
 [18] compute_axes_grid(d::Layer; axis::@NamedTuple{}, palettes::@NamedTuple{})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/algebra/layers.jl:114
 [19] compute_axes_grid
    @ ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/algebra/layers.jl:110 [inlined]
 [20] compute_axes_grid(fig::Figure, d::Layer; axis::@NamedTuple{}, palettes::@NamedTuple{})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/algebra/layers.jl:100
 [21] compute_axes_grid
    @ ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/algebra/layers.jl:97 [inlined]
 [22] #245
    @ ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/draw.jl:21 [inlined]
 [23] update
    @ ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/draw.jl:10 [inlined]
 [24] plot!(fig::Figure, d::Layer; axis::@NamedTuple{}, palettes::@NamedTuple{})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/draw.jl:21
 [25] plot!
    @ ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/draw.jl:16 [inlined]
 [26] (::AlgebraOfGraphics.var"#249#250"{…})(f::Figure)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/draw.jl:48
 [27] update
    @ ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/draw.jl:10 [inlined]
 [28] #draw#248
    @ ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/draw.jl:47 [inlined]
 [29] draw(d::Layer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/MqbNU/src/draw.jl:44
 [30] top-level scope

Images

Desired plot:

download

Version info

julia> versioninfo()
Julia Version 1.10.2
Commit bd47eca2c8a (2024-03-01 10:14 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M2
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 4 default, 0 interactive, 2 GC (on 4 virtual cores)
Environment:
  JULIA_NUM_THREADS = 4
  JULIA_EDITOR = code

(Scratchpad) pkg> st
Status `~/Documents/Scratchpad/Project.toml`
  [cbdf2221] AlgebraOfGraphics v0.6.18
  [13f3f980] CairoMakie v0.11.9
  [a93c6f00] DataFrames v1.6.1
  [9a3f8284] Random

rben01 avatar Apr 02 '24 21:04 rben01