Open goretkin opened 4 years ago
Here's a simpler example:
using Plots
using OffsetArrays
z = OffsetArray(ones(5)*(1:4)', (-3,-2))
heatmap(z) # fails
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: DimensionMismatch("new dimensions (4,) must be consistent with array size 20")
Stacktrace:
[1] (::Base.var"#throw_dmrsa#234")(dims::Tuple{Int64}, len::Int64)
@ Base ./reshapedarray.jl:41
[2] reshape
@ ./reshapedarray.jl:45 [inlined]
[3] reshape
@ ~/.julia/packages/OffsetArrays/EYLoR/src/OffsetArrays.jl:357 [inlined]
[4] nonuniformcellarray(x::Vector{Float64}, y::Vector{Float64}, dimx::Int64, dimy::Int64, color::OffsetMatrix{Int32, Matrix{Int32}})
@ GR ~/.julia/packages/GR/4DHy8/src/GR.jl:881
[5] gr_draw_heatmap(series::Plots.Series, x::Vector{Float64}, y::Vector{Float64}, z::OffsetMatrix{Float64, Matrix{Float64}}, clims::Tuple{Float64, Float64})
@ Plots ~/.julia/packages/Plots/FKcum/src/backends/gr.jl:1861
[6] gr_add_series(sp::Plots.Subplot{Plots.GRBackend}, series::Plots.Series)
@ Plots ~/.julia/packages/Plots/FKcum/src/backends/gr.jl:1665
[7] gr_display(sp::Plots.Subplot{Plots.GRBackend}, w::Measures.AbsoluteLength, h::Measures.AbsoluteLength, viewport_canvas::Vector{Float64})
...
Using: [91a5bcdd] Plots v1.16.5
Here's my current workaround, in case it helps others:
using Plots
using OffsetArrays
z = OffsetArray(ones(5)*(1:4)', (-3,-2))
function Plots.heatmap(z::OffsetMatrix{<:Number}; kwargs...)
x = axes(z,1); x = x.parent .+ x.offset
y = axes(z,2); y = y.parent .+ y.offset
heatmap(x, y, OffsetArrays.no_offset_view(z); kwargs...)
end
heatmap(z, title="it works")
This doesn't seem to work neither with the GR backend (output below) or the PyPlot backend (stacktrace below).
PyPlot:
GR:
I have
Related: https://github.com/JuliaPlots/Plots.jl/pull/2304