diff --git a/src/backends/gr.jl b/src/backends/gr.jl index b9a09d61..989a0751 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -586,7 +586,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end if st == :heatmap outside_ticks = true - x, y = heatmap_edges(series[:x]), heatmap_edges(series[:y]) + x, y = heatmap_edges(series[:x], sp[:xaxis][:scale]), heatmap_edges(series[:y], sp[:yaxis][:scale]) xy_lims = x[1], x[end], y[1], y[end] expand_extrema!(sp[:xaxis], x) expand_extrema!(sp[:yaxis], y) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 251b6377..9f5e8a24 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -768,7 +768,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end if st == :heatmap - x, y, z = heatmap_edges(x), heatmap_edges(y), transpose_z(series, z.surf) + x, y, z = heatmap_edges(x, sp[:xaxis][:scale]), heatmap_edges(y, sp[:yaxis][:scale]), transpose_z(series, z.surf) expand_extrema!(sp[:xaxis], x) expand_extrema!(sp[:yaxis], y) diff --git a/src/utils.jl b/src/utils.jl index d49b1fc7..2b0720fe 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -332,11 +332,24 @@ Base.first(x::Symbol) = x sortedkeys(d::Dict) = sort(collect(keys(d))) + +const _scale_base = Dict{Symbol, Real}( + :log10 => 10, + :log2 => 2, + :ln => e, +) + "create an (n+1) list of the outsides of heatmap rectangles" -function heatmap_edges(v::AVec) +function heatmap_edges(v::AVec, scale::Symbol = :identity) vmin, vmax = ignorenan_extrema(v) - extra = 0.5 * (vmax-vmin) / (length(v)-1) - vcat(vmin-extra, 0.5 * (v[1:end-1] + v[2:end]), vmax+extra) + extra_min = extra_max = 0.5 * (vmax-vmin) / (length(v)-1) + if scale in _logScales + vmin > 0 || error("The axis values must be positive for a $scale scale") + while vmin - extra_min <= 0 + extra_min /= _scale_base[scale] + end + end + vcat(vmin-extra_min, 0.5 * (v[1:end-1] + v[2:end]), vmax+extra_max) end