Skip to content

Commit

Permalink
Fix heatmap! (#551)
Browse files Browse the repository at this point in the history
* Fix heatmap! function in Makie

* Add tests for all Makie bang functions

This also switches to using plain Makie. This should enable using Makie testing on CI.

* Enable Makie testing on CI

* Try testing with CairoMakie for CI

* Remove show

* Skip currently broken tests

* Remove commented CI check

* Fix volume! and volumesclices!

* Add todos for the commented tests
  • Loading branch information
felixcremer authored Oct 18, 2023
1 parent 94d1477 commit e948e16
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 62 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ julia = "1.6"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand All @@ -64,4 +65,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[targets]
test = ["Aqua", "ArrayInterface", "BenchmarkTools", "Combinatorics", "CoordinateTransformations", "DataFrames", "Distributions", "Documenter", "ImageFiltering", "ImageTransformations", "OffsetArrays", "Plots", "Random", "SafeTestsets", "StatsPlots", "Test", "Unitful"]
test = ["Aqua", "ArrayInterface", "BenchmarkTools", "Combinatorics", "CoordinateTransformations", "DataFrames", "Distributions", "Documenter", "ImageFiltering", "ImageTransformations", "CairoMakie", "OffsetArrays", "Plots", "Random", "SafeTestsets", "StatsPlots", "Test", "Unitful"]
9 changes: 5 additions & 4 deletions ext/DimensionalDataMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ function _pointbased1(A, attributes; set_axis_attributes=true)
lookup_attributes, newdims = _split_attributes(A1)
A2 = _restore_dim_names(set(A1, newdims[1] => newdims[1]), A)
args = Makie.convert_arguments(Makie.PointBased(), A2)

# Plot attribute generation
user_attributes = Makie.Attributes(; attributes...)
axis_attributes = if set_axis_attributes
Expand All @@ -107,7 +106,9 @@ function _pointbased1(A, attributes; set_axis_attributes=true)
label=DD.label(A),
)
merged_attributes = merge(user_attributes, axis_attributes, plot_attributes, lookup_attributes)

if !set_axis_attributes
delete!(merged_attributes, :axis)
end
return args, merged_attributes
end

Expand Down Expand Up @@ -153,7 +154,7 @@ for (f1, f2) in _paired(:plot => :heatmap, :heatmap, :image, :contour, :contourf
x=nothing, y=nothing, colorbarkw=(;), attributes...
)
replacements = _keywords2dimpairs(x, y)
args, _ = _surface2(A, attributes, replacements)
_, _, args, _ = _surface2(A, attributes, replacements)
# No ColourBar in the ! in-place versions
return Makie.$f2!(args...; attributes...)
end
Expand Down Expand Up @@ -206,7 +207,7 @@ for (f1, f2) in _paired(:plot => :volume, :volume, :volumeslices)
end
function Makie.$f1!(axis, A::AbstractDimArray{<:Any,3}; x=nothing, y=nothing, z=nothing, attributes...)
replacements = _keywords2dimpairs(x, y, z)
_, args, _ = _volume3(A, attributes, replacements)
_, _, args, _ = _volume3(A, attributes, replacements)
return Makie.$f2!(axis, args...; attributes...)
end
end
Expand Down
159 changes: 102 additions & 57 deletions test/plotrecipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,79 +157,124 @@ nothing
# da_im2 = DimArray(im2, (X(10:10:100), Y(10:10:100)), "Image")
# da_im2 |> plot

if !haskey(ENV, "CI")

using GLMakie
using CairoMakie: CairoMakie as M
@testset "Makie" begin
# 1d
A1 = rand(X('a':'e'); name=:test)
A1m = rand([missing, (1:3)...], X('a':'e'); name=:test)
A1m = rand([missing, (1:3.)...], X('a':'e'); name=:test)
A1m .= A1
A1m[3] = missing
plot(A1)
plot(A1m)
scatter(A1)
scatter(A1m)
lines(A1)
lines(A1m)
scatterlines(A1)
scatterlines(A1m)
stairs(A1)
stairs(A1m)
stem(A1)
stem(A1m)
barplot(A1)
barplot(A1m)
waterfall(A1)
waterfall(A1m)
fig, ax, _ = M.plot(A1)
M.plot!(ax, A1)
fig, ax, _ = M.plot(A1m)
M.plot!(ax, A1m)
fig, ax, _ = M.scatter(A1)
M.scatter!(ax, A1)
fig, ax, _ = M.scatter(A1m)
M.scatter!(ax, A1m)
fig, ax, _ = M.lines(A1)
M.lines!(ax, A1)
fig, ax, _ = M.lines(A1m)
M.lines!(ax, A1m)
fig, ax, _ = M.scatterlines(A1)
M.scatterlines!(ax, A1)
fig, ax, _ = M.scatterlines(A1m)
M.scatterlines!(ax, A1m)
fig, ax, _ = M.stairs(A1)
M.stairs!(ax, A1)
fig, ax, _ = M.stairs(A1m)
M.stairs!(ax, A1m)
fig, ax, _ = M.stem(A1)
M.stem!(ax, A1)
fig, ax, _ = M.stem(A1m)
M.stem!(ax, A1m)
fig, ax, _ = M.barplot(A1)
M.barplot!(ax, A1)
fig, ax, _ = M.barplot(A1m)
M.barplot!(ax, A1m)
fig, ax, _ = M.waterfall(A1)
M.waterfall!(ax, A1)
fig, ax, _ = M.waterfall(A1m)
M.waterfall!(ax, A1m)
# 2d
A2 = rand(X(10:10:100), Y(['a', 'b', 'c']))
A2r = rand(Y(10:10:100), X(['a', 'b', 'c']))
A2m = rand([missing, (1:5)...], Y(10:10:100), X(['a', 'b', 'c']))
A2m[3] = missing
plot(A2)
plot(A2m)
# Categorical wins: it's on x, even though its Y
boxplot(A2)
boxplot(A2r)
@test_throws ArgumentError boxplot(A2m)
violin(A2)
violin(A2r)
@test_throws ArgumentError violin(A2m)
rainclouds(A2)
@test_throws ErrorException rainclouds(A2m)
surface(A2)
surface(A2m)
fig, ax, _ = M.plot(A2)
M.plot!(ax, A2)
fig, ax, _ = M.plot(A2m)
M.plot!(ax, A2m)
fig, ax, _ = M.violin(A2r)
M.violin!(ax, A2r)
@test_throws ArgumentError M.violin(A2m)
@test_throws ArgumentError M.violin!(ax, A2m)

fig, ax, _ = M.rainclouds(A2)
M.rainclouds!(ax, A2)
@test_throws ErrorException M.rainclouds(A2m)
@test_throws ErrorException M.rainclouds!(ax, A2m)

fig, ax, _ = M.surface(A2)
M.surface!(ax, A2)
fig, ax, _ = M.surface(A2m)
M.surface!(ax, A2m)
# Series also puts Categories in the legend no matter where they are
series(A2)
series(A2r)
series(A2r; labeldim=Y)
series(A2m)
@test_throws ArgumentError plot(A2; y=:c)
fig, ax, _ = M.series(A2)
M.series!(ax, A2)
fig, ax, _ = M.series(A2r)
M.series!(ax, A2r)
#TODO: uncomment when the Makie version gets bumped
#fig, ax, _ = M.series(A2r; labeldim=Y)
#M.series!(ax, A2r; labeldim=Y)
fig, ax, _ = M.series(A2m)
M.series!(ax, A2m)
@test_throws ArgumentError M.plot(A2; y=:c)
@test_throws ArgumentError M.plot!(ax, A2; y=:c)

# x/y can be specified
A2ab = DimArray(rand(6, 10), (:a, :b); name=:stuff)
plot(A2ab)
contourf(A2ab; x=:a)
heatmap(A2ab; y=:b)
series(A2ab)
boxplot(A2ab)
violin(A2ab)
rainclouds(A2ab)
surface(A2ab)
series(A2ab)
series(A2ab; labeldim=:a)
series(A2ab; labeldim=:b)
fig, ax, _ = M.plot(A2ab)
M.plot!(ax, A2ab)
fig, ax, _ = M.contourf(A2ab; x=:a)
M.contourf!(ax, A2ab, x=:a)
fig, ax, _ = M.heatmap(A2ab; y=:b)
M.heatmap!(ax, A2ab; y=:b)
fig, ax, _ = M.series(A2ab)
M.series!(ax, A2ab)
fig, ax, _ = M.boxplot(A2ab)
M.boxplot!(ax, A2ab)
fig, ax, _ = M.violin(A2ab)
M.violin!(ax, A2ab)
fig, ax, _ = M.rainclouds(A2ab)
M.rainclouds!(ax, A2ab)
fig, ax, _ = M.surface(A2ab)
M.surface!(ax, A2ab)
fig, ax, _ = M.series(A2ab)
M.series!(ax, A2ab)
fig, ax, _ = M.series(A2ab; labeldim=:a)
M.series!(ax, A2ab; labeldim=:a)
# TODO: this is currently broken in Makie
# should be uncommented with the bump of the Makie version
#fig, ax, _ = M.series(A2ab; labeldim=:b)
#M.series!(ax, A2ab;labeldim=:b)

# 3d
A3 = rand(X(7), Z(10), Y(5))
A3m = rand([missing, (1:7)...], X(7), Z(10), Y(5))
A3m[3] = missing
volume(A3)
volume(A3m)
volumeslices(A3)
volumeslices(A3m)
fig, ax, _ = M.volume(A3)
M.volume!(ax, A3)
fig, ax, _ = M.volume(A3m)
M.volume!(ax, A3m)
fig, ax, _ = M.volumeslices(A3)
M.volumeslices!(ax, A3)
fig, ax, _ = M.volumeslices(A3m)
M.volumeslices!(ax, A3m)
# x/y/z can be specified
A3abc = DimArray(rand(10, 10, 7), (:a, :b, :c); name=:stuff)
volume(A3abc; x=:c)
volumeslices(A3abc; z=:a)
end

fig, ax, _ = M.volume(A3abc; x=:c)
fig, ax, _ = M.volumeslices(A3abc; x=:c)
fig, ax, _ = M.volumeslices(A3abc; z=:a)
M.volumeslices!(ax, A3abc;z=:a)
end

0 comments on commit e948e16

Please sign in to comment.