diff --git a/Project.toml b/Project.toml index 4b41ed7db..91ebb999b 100644 --- a/Project.toml +++ b/Project.toml @@ -7,6 +7,7 @@ version = "1.40.16" Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" Contour = "d38c429a-6771-53c6-b99e-75d170b6e991" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" +Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94" Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" FFMPEG = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" @@ -58,6 +59,7 @@ UnitfulExt = "Unitful" [compat] Aqua = "0.8" Contour = "0.5 - 0.6" +Dierckx = "0.5.4" Downloads = "1" FFMPEG = "0.4.1" FixedPointNumbers = "0.6 - 0.8" diff --git a/src/pipeline.jl b/src/pipeline.jl index 72ec7c263..23babb447 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -1,5 +1,5 @@ # RecipesPipeline API - +using Dierckx ## Warnings function RecipesPipeline.warn_on_recipe_aliases!( @@ -374,11 +374,35 @@ function RecipesPipeline.add_series!(plt::Plot, plotattributes) plotattributes[letter1], plotattributes[letter2] = plotattributes[letter2], plotattributes[letter1] end + if plotattributes[:seriestype] === :heatmap + if haskey(plotattributes, :interpolate) + s = plotattributes[:interpolate] + x = collect(plotattributes[:x]) + y = collect(plotattributes[:y]) + z = reshape(collect(plotattributes[:z]),4,4) + finerx, finery, zinterp = cubic_interp_2d( x, y, z, s ) + plotattributes[:x] = finerx + plotattributes[:y] = finery + plotattributes[:z] = Surface(zinterp) + plotattributes[:size] = (length(finerx), length(finery)) + end + end _expand_subplot_extrema(sp, plotattributes, plotattributes[:seriestype]) _update_series_attributes!(plotattributes, plt, sp) return _add_the_series(plt, sp, plotattributes) end +function cubic_interp_2d( x, y, data, s ) + spl = Spline2D(y, x, data; kx=3, ky=3, s=0.0) + finerx = LinRange(x[1], x[end], s[1]) + finery = LinRange(y[1], y[end], s[2]) + data_interp = Array{Float64}(undef, s[2], s[1]) + for (i,yint) ∈ enumerate(finery), (j,xint) ∈ enumerate(finerx) + data_interp[i,j] = evaluate(spl, yint, xint) + end + return finerx, finery, data_interp +end + # getting ready to add the series... last update to subplot from anything # that might have been added during series recipes function _prepare_subplot(plt::Plot{T}, plotattributes::AKW) where {T} diff --git a/test/test_misc.jl b/test/test_misc.jl index a5ee276a6..3d0fafff4 100644 --- a/test/test_misc.jl +++ b/test/test_misc.jl @@ -351,4 +351,13 @@ Plots.with(:gr) do show(devnull, scatter(x, y)) # show(devnull, plot(x, y)) # currently unsupported end + + @testset "heatmap interpolation" begin + @test heatmap( + 1:4, + 1:4, + [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]; + interpolate = (10, 10), + ) + end end