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

Implement the generalized Arrays interface (OffsetArrays) #1259

Open
yakir12 opened this issue Aug 25, 2021 · 6 comments
Open

Implement the generalized Arrays interface (OffsetArrays) #1259

yakir12 opened this issue Aug 25, 2021 · 6 comments
Labels
conversions Mainly `convert_arguments` enhancement Feature requests and enhancements lines Makie Backend independent issues (Makie core) scatter

Comments

@yakir12
Copy link
Contributor

yakir12 commented Aug 25, 2021

Makie should be able to plot the generalized Arrays interface to be compatible with e.g. OffsetArrays.

Currently,

using OffsetArrays, GLMakie
xy = OffsetArray(rand(100), -50)
lines(xy)

results in:

ERROR: DimensionMismatch("arrays could not be broadcast to a common size; got a dimension with lengths 100 and 100")
Stacktrace:
  [1] _bcs1(a::Base.OneTo{Int64}, b::OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}})
    @ Base.Broadcast ./broadcast.jl:516
  [2] _bcs
    @ ./broadcast.jl:510 [inlined]
  [3] broadcast_shape
    @ ./broadcast.jl:504 [inlined]
  [4] combine_axes
    @ ./broadcast.jl:499 [inlined]
  [5] instantiate
    @ ./broadcast.jl:281 [inlined]
  [6] materialize
    @ ./broadcast.jl:904 [inlined]
  [7] convert_arguments(P::PointBased, x::UnitRange{Int64}, y::OffsetVector{Float64, Vector{Float64}})
    @ Makie ~/.julia/packages/Makie/NL7Xw/src/conversions.jl:128
  [8] convert_arguments
    @ ~/.julia/packages/Makie/NL7Xw/src/conversions.jl:139 [inlined]
  [9] convert_arguments(T::Type{Lines{Tuple{OffsetVector{Float64, Vector{Float64}}}}}, args::OffsetVector{Float64, Vector{Float64}}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/packages/Makie/NL7Xw/src/conversions.jl:10
 [10] convert_arguments
    @ ~/.julia/packages/Makie/NL7Xw/src/conversions.jl:8 [inlined]
 [11] plot!(scene::Scene, P::Type{Lines}, attributes::Attributes, args::OffsetVector{Float64, Vector{Float64}}; kw_attributes::Base.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:show_axis,), Tuple{Bool}}})
    @ Makie ~/.julia/packages/Makie/NL7Xw/src/interfaces.jl:321
 [12] plot(P::Type{Lines}, args::OffsetVector{Float64, Vector{Float64}}; axis::NamedTuple{(), Tuple{}}, figure::NamedTuple{(), Tuple{}}, kw_attributes::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/packages/Makie/NL7Xw/src/figureplotting.jl:28
 [13] plot
    @ ~/.julia/packages/Makie/NL7Xw/src/figureplotting.jl:18 [inlined]
 [14] #lines#31
    @ ~/.julia/packages/MakieCore/S8PkO/src/recipes.jl:31 [inlined]
 [15] lines(args::OffsetVector{Float64, Vector{Float64}})
    @ MakieCore ~/.julia/packages/MakieCore/S8PkO/src/recipes.jl:31
 [16] top-level scope
    @ REPL[384]:1

To plot this data we need to:

x = keys(xy)
y = values(xy)
lines(x, y)
@SimonDanisch
Copy link
Member

I guess this can be fixed by using keys(y) here:
https://github.com/JuliaPlots/Makie.jl/blob/master/src/conversions.jl#L139

@yakir12
Copy link
Contributor Author

yakir12 commented Aug 25, 2021

You guessed right!

@goretkin
Copy link
Contributor

goretkin commented Nov 15, 2021

[EDIT] That PR is a step toward fixing the example below, but as noted there, does not yet fix heatmap.

Another example

using Makie
using OffsetArrays
fig = Figure()
ax = Axis(fig[1, 1], title = "Demo")
heatmap!(ax, fill(0.0, (-10:10, -10:10)))

gives this on the current release (does not include #1260)

ulia> heatmap!(ax, fill(0.0, (-10:10, -10:10)))
ERROR: TypeError: in typeassert, expected Matrix{Float32}, got a value of type OffsetMatrix{Float32, Matrix{Float32}}
Stacktrace:
  [1] el32convert(x::OffsetMatrix{Float64, Matrix{Float64}})
    @ Makie ~/.julia/packages/Makie/gQOQF/src/conversions.jl:601
  [2] convert_arguments(#unused#::DiscreteSurface, data::OffsetMatrix{Float64, Matrix{Float64}})
    @ Makie ~/.julia/packages/Makie/gQOQF/src/conversions.jl:312
  [3] convert_arguments(T::Type{Heatmap{Tuple{OffsetMatrix{Float64, Matrix{Float64}}}}}, args::OffsetMatrix{Float64, Matrix{Float64}}; kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/packages/Makie/gQOQF/src/conversions.jl:10
  [4] convert_arguments
    @ ~/.julia/packages/Makie/gQOQF/src/conversions.jl:8 [inlined]
  [5] plot!(scene::Scene, P::Type{Heatmap{ArgType} where ArgType}, attributes::Attributes, args::OffsetMatrix{Float64, Matrix{Float64}}; kw_attributes::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/packages/Makie/gQOQF/src/interfaces.jl:321
  [6] plot!(scene::Scene, P::Type{Heatmap{ArgType} where ArgType}, attributes::Attributes, args::OffsetMatrix{Float64, Matrix{Float64}})
    @ Makie ~/.julia/packages/Makie/gQOQF/src/interfaces.jl:308
  [7] plot!(la::Axis, P::Type{Heatmap{ArgType} where ArgType}, attributes::Attributes, args::OffsetMatrix{Float64, Matrix{Float64}}; kw_attributes::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie.MakieLayout ~/.julia/packages/Makie/gQOQF/src/makielayout/layoutables/axis.jl:658
  [8] plot!
    @ ~/.julia/packages/Makie/gQOQF/src/makielayout/layoutables/axis.jl:653 [inlined]
  [9] plot!(P::Type{Heatmap{ArgType} where ArgType}, ax::Axis, args::OffsetMatrix{Float64, Matrix{Float64}}; kw_attributes::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie.MakieLayout ~/.julia/packages/Makie/gQOQF/src/makielayout/layoutables/axis.jl:670
 [10] plot!(P::Type{Heatmap{ArgType} where ArgType}, ax::Axis, args::OffsetMatrix{Float64, Matrix{Float64}})
    @ Makie.MakieLayout ~/.julia/packages/Makie/gQOQF/src/makielayout/layoutables/axis.jl:669
 [11] heatmap!(::Axis, ::Vararg{Any, N} where N; attributes::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ MakieCore ~/.julia/packages/MakieCore/S8PkO/src/recipes.jl:35
 [12] heatmap!(::Axis, ::Vararg{Any, N} where N)
    @ MakieCore ~/.julia/packages/MakieCore/S8PkO/src/recipes.jl:35
 [13] top-level scope
    @ REPL[28]:1

@ffreyer ffreyer added enhancement Feature requests and enhancements Makie Backend independent issues (Makie core) conversions Mainly `convert_arguments` labels Aug 22, 2024
@ffreyer
Copy link
Collaborator

ffreyer commented Aug 22, 2024

Is this a regression at this point?

@asinghvi17
Copy link
Member

I guess it's not a regression so much as it never worked correctly in the first place. I have a PR up for that but should restart discussion at some point.

@asinghvi17
Copy link
Member

asinghvi17 commented Aug 26, 2024

The heatmap example fails on master because numbers_to_colors can't handle offset arrays in its return type. We should force a regular array in numbers_to_colors.

 fig
Error showing value of type Figure:
ERROR: MethodError: Cannot `convert` an object of type
  OffsetMatrix{ColorTypes.RGBA{Float32}, Matrix{ColorTypes.RGBA{Float32}}} to an object of type
  Union{ColorTypes.RGBA{Float32}, Matrix{ColorTypes.RGBA{Float32}}}

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84

Stacktrace:
  [1] numbers_to_colors(numbers::OffsetMatrix{…}, colormap::Vector{…}, colorscale::Function, colorrange::Vec{…}, lowclip::ColorTypes.RGBA{…}, highclip::ColorTypes.RGBA{…}, nan_color::ColorTypes.RGBA{…})
    @ Makie ~/.julia/dev/Makie/src/colorsampler.jl:163
  [2] to_color(c::Makie.ColorMapping{2, OffsetMatrix{Float32, Matrix{Float32}}, OffsetMatrix{Float32, Matrix{Float32}}})
    @ Makie ~/.julia/dev/Makie/src/colorsampler.jl:346
  [3] draw_atomic(scene::Scene, screen::CairoMakie.Screen{CairoMakie.IMAGE}, primitive::Union{Image, Heatmap})
    @ CairoMakie ~/.julia/dev/Makie/CairoMakie/src/primitives.jl:805

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conversions Mainly `convert_arguments` enhancement Feature requests and enhancements lines Makie Backend independent issues (Makie core) scatter
Projects
None yet
Development

No branches or pull requests

5 participants