-
Notifications
You must be signed in to change notification settings - Fork 25
Conversation
Tests passed locally. |
I never really took note of this, we should try to get this in! But I want to tackle the problem with centering at the same time, so that bins are centered on the values in the x and y ranges. I think for that, changes in AbstractPlotting regarding the heatmap conversion pipeline might be necessary? |
I think that's just a question of where we want to deal with that. Do we want backends to assume every heat map is centered? Should every heatmap be centered, even It would be good if To avoid sitting on this for another 5 months, maybe we should just say a heatmap in always centered for now, and work out the details later. It should be fine to handle that in the backends. |
These all work as expected: (still without centering) heatmap(rand(10, 10))
heatmap(1..2, 1..3, rand(10, 10))
heatmap(1:10, 1:10, rand(10, 10))
heatmap(1:10, [1,3,4,5,6,8,10,14,15,20], rand(10, 10))
heatmap([1,2,3,4,5,10,11,12,13,20], [1,3,4,5,6,8,10,14,15,20], rand(10, 10)) |
And
results in |
For shifting I copied what I had in MakieOrg/Makie.jl#675. |
I had proposed earlier to use an |
heatmap(rand(3, 3)) # centered on 1 to centered on 3 in both dimensions
heatmap(1:3, 1:3, rand(3, 3)) # same
heatmap(1..3, 1..3, rand(3, 3)) # same
heatmap([1, 2, 4], [1, 3, 5], rand(3, 3)) # unequal cell sizes, still giving the centers
heatmap(Edges(1..3), Edges(1..3), rand(3, 3)) # now the edges go from 1 to 3, not the centers
heatmap(Edges(1..3, 1..3), rand(3, 3)) # same, maybe more convenient with only one `Edges`
heatmap(Edges([1, 2, 4, 5], [2, 5, 6, 7]), rand(3, 3)) # unequal cell sizes This seems doable, but I'm not sure what I'd have to do in AbstractPlotting to make it work. In GLMakie it would be nice to have separate |
src/drawing_primitives.jl
Outdated
gl_attributes[:position_x] = if to_value(x[1]) isa Vector | ||
map(x[1]) do v | ||
# Equivalent to | ||
# mids = 0.5 .* (v[1:end-1] .+ v[2:end]) | ||
# borders = [2v[1] - mids[1]; mids; 2v[end] - mids[end]] | ||
borders = [0.5 * (v[max(1, i)] + v[min(end, i+1)]) for i in 0:length(v)] | ||
borders[1] = 2borders[1] - borders[2] | ||
borders[end] = 2borders[end] - borders[end-1] | ||
Texture(el32convert(borders), minfilter = :nearest) | ||
end | ||
else | ||
map(x[1]) do _x | ||
min, max = to_range(_x) | ||
N = size(to_value(x[3]), 1) | ||
halfstep = 0.5 * (max - min) / (N-1) | ||
a = collect(range(min-halfstep, max+halfstep, length=N+1)) | ||
Texture(el32convert(a); minfilter=:nearest) | ||
end | ||
end | ||
gl_attributes[:position_y] = if to_value(x[2]) isa Vector | ||
map(x[2]) do v | ||
borders = [0.5 * (v[max(1, i)] + v[min(end, i+1)]) for i in 0:length(v)] | ||
borders[1] = 2borders[1] - borders[2] | ||
borders[end] = 2borders[end] - borders[end-1] | ||
Texture(el32convert(borders), minfilter = :nearest) | ||
end | ||
else | ||
map(x[2]) do _x | ||
min, max = to_range(_x) | ||
N = size(to_value(x[3]), 2) | ||
halfstep = 0.5 * (max - min) / (N-1) | ||
a = collect(range(min-halfstep, max+halfstep, length=N+1)) | ||
Texture(el32convert(a); minfilter=:nearest) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With Edges{Vector}
this would turn into just
gl_attributess[:position_x] = map(e -> Texture(el32convert(e.data), minfilter = :nearest), x[1])
gl_attributess[:position_y] = map(e -> Texture(el32convert(e.data), minfilter = :nearest), x[2])
Edges{<:AbstractRange}
and Edges{<:Interval}
could use some implementation based on Grid
like surface, but I think there are also changes to the shader that need to happen. So maybe we just convert to Vector here for now, and optimize this later. So
gl_attributess[:position_x] = map(x[1]) do e
if e.data isa Vector
Texture(el32convert(e.data), minfilter = :nearest)
else
min, max = to_range(e.data)
N = size(to_value(x[3], 1)
Texture(el32convert(collect(range(min, max, length=N))), minfilter = :nearest)
end
...
I adjusted things to work with JuliaPlots/AbstractPlotting.jl#727. Now heatmap assumes vector inputs for x and y, which means it won't work without 727. |
I need to recover the Interval methods because they still make it through |
|
See MakieOrg/Makie.jl#675 and JuliaPlots/CairoMakie.jl#111
Currently works with irregular vectors such as in the example from the issue. Still working on getting all the other inputs to work.