diff --git a/src/UnicodePlots.jl b/src/UnicodePlots.jl index 9679416d..5ee68184 100644 --- a/src/UnicodePlots.jl +++ b/src/UnicodePlots.jl @@ -73,7 +73,7 @@ export scatterplot!, stairs # methods without mutating variants -export horizontal_histogram, vertical_histogram, histogram, heatmap, spy, imageplot +export horizontal_histogram, vertical_histogram, histogram, polarheatmap, heatmap, spy, imageplot include("common.jl") include("lut.jl") @@ -113,6 +113,7 @@ include("interface/heatmap.jl") include("interface/spy.jl") include("interface/boxplot.jl") include("interface/polarplot.jl") +include("interface/polarheatmap.jl") include("interface/imageplot.jl") function __init__() diff --git a/src/interface/polarheatmap.jl b/src/interface/polarheatmap.jl new file mode 100644 index 00000000..24b95a9b --- /dev/null +++ b/src/interface/polarheatmap.jl @@ -0,0 +1,25 @@ +""" +# Author(s) + +- T Bltg (github.com/t-bltg) + +# Examples + +""" +function polarheatmap( + θ::AbstractVector, + r::Union{Function,AbstractVector}, + A::Union{Function,AbstractVecOrMat}; + rlim = (0, 0), + kw... +) + r, lims = polar_lims(θ, r, rlim) + A = A isa Function ? A.(θ, r) : A + + # reuse polarplot to draw the grid + plot = polarplot(zero(lims), lims) + + # use vec(A) ..., should we add yet another canvas ?? + + plot +end \ No newline at end of file diff --git a/src/interface/polarplot.jl b/src/interface/polarplot.jl index 27335bad..0369c7af 100644 --- a/src/interface/polarplot.jl +++ b/src/interface/polarplot.jl @@ -62,13 +62,10 @@ function polarplot( kw..., ) pkw, okw = split_plot_kw(kw) - - r = r isa Function ? r.(θ) : r - max_r = last(is_auto(rlim) ? extrema(r) : rlim) - lims = x = y = [-max_r, +max_r] + r, lims = polar_lims(θ, r, rlim) plot = Plot( - x, - y; + lims, + lims; xlim = lims, ylim = lims, grid = false, @@ -92,26 +89,23 @@ end scatter = false, kw..., ) - mr, Mr = is_auto(rlim) ? extrema(r) : rlim + mr, Mr = rlim = collect(rlim) # grid theta = range(0, 2π, length = 360) - grid_color = BORDER_COLOR[] - lineplot!(plot, Mr * cos.(theta), Mr * sin.(theta), color = grid_color) + color = BORDER_COLOR[] + lineplot!(plot, Mr * cos.(theta), Mr * sin.(theta); color) for theta ∈ 0:(π / 4):(2π) - lineplot!(plot, [mr, Mr] .* cos(theta), [mr, Mr] .* sin(theta); color = grid_color) + lineplot!(plot, rlim .* cos(theta), rlim .* sin(theta); color) end - # user data - (scatter ? scatterplot! : lineplot!)(plot, r .* cos.(θ), r .* sin.(θ); kw...) - # labels row = ceil(Int, nrows(plot.graphics) / 2) - label!(plot, :r, row, degrees ? "0°" : "0", color = grid_color) - label!(plot, :t, degrees ? "90°" : "π / 2", color = grid_color) - label!(plot, :l, row, degrees ? "180°" : "π", color = grid_color) - label!(plot, :b, degrees ? "270°" : "3π / 4", color = grid_color) + label!(plot, :r, row, degrees ? "0°" : "0"; color) + label!(plot, :t, degrees ? "90°" : "π / 2"; color) + label!(plot, :l, row, degrees ? "180°" : "π"; color) + label!(plot, :b, degrees ? "270°" : "3π / 4"; color) for r ∈ range(mr, Mr, length = num_rad_lab) annotate!( @@ -119,8 +113,19 @@ end r * cos(ang_rad_lab), r * sin(ang_rad_lab), isinteger(r) ? string(round(Int, r)) : @sprintf("%.1f", r); - color = grid_color, + color, ) end + + # user data + (scatter ? scatterplot! : lineplot!)(plot, r .* cos.(θ), r .* sin.(θ); kw...) + plot end + +function polar_lims(θ::AbstractVector, r::Union{Function,AbstractVector}, rlim) + r = r isa Function ? r.(θ) : r + r_max = last(is_auto(rlim) ? extrema(r) : rlim) + lims = x = y = [-r_max, +r_max] + r, lims +end diff --git a/test/runtests.jl b/test/runtests.jl index afdc32fd..1a651887 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -124,6 +124,7 @@ withenv("FORCE_COLOR" => "X") do # JuliaPlots/UnicodePlots.jl/issues/134 @timeit_include "tst_boxplot.jl" @timeit_include "tst_contourplot.jl" @timeit_include "tst_polarplot.jl" + @timeit_include "tst_polarheatmap.jl" @timeit_include "tst_heatmap.jl" @timeit_include "tst_volume.jl" @timeit_include "tst_surfaceplot.jl" diff --git a/test/tst_polarheatmap.jl b/test/tst_polarheatmap.jl new file mode 100644 index 00000000..3018bd16 --- /dev/null +++ b/test/tst_polarheatmap.jl @@ -0,0 +1,8 @@ +@testset "simple" begin + θ = range(0, 2π; length = 100) + r = range(0, 120; length = 50) + A = sin.(r ./ 10) .* (cos.(θ))' + p = polarheatmap(θ, r, A) + + test_ref("polarheatmap/simple.txt", @show_col(p)) +end