diff --git a/src/args.jl b/src/args.jl index 8c6b1f0a..82ca09d8 100644 --- a/src/args.jl +++ b/src/args.jl @@ -345,7 +345,7 @@ const _subplot_defaults = KW( :legendtitlefontcolor => :match, :annotations => [], # annotation tuples... list of (x,y,annotation) :projection => :none, # can also be :polar or :3d - :aspect_ratio => :none, # choose from :none or :equal + :aspect_ratio => :auto, # choose from :none or :equal :margin => 1mm, :left_margin => :match, :top_margin => :match, diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 8e1c833d..02aae37e 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -981,7 +981,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) data_lims = gr_xy_axislims(sp) xy_lims = data_lims - ratio = sp[:aspect_ratio] + ratio = get_aspect_ratio(sp) if ratio != :none if ratio == :equal ratio = 1 diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 7205b850..276ad8dd 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -470,7 +470,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) push!(style, string("title style = {font = ", pgf_font(sp[:titlefontsize], pgf_thickness_scaling(sp)), ", color = ", cstr, ", draw opacity = ", α, ", rotate = ", sp[:titlefontrotation], "}")) end - if sp[:aspect_ratio] in (1, :equal) + if get_aspect_ratio(sp) in (1, :equal) kw[:axisEqual] = "true" end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 47f03771..26a27f75 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -108,7 +108,7 @@ function shrink_by(lo, sz, ratio) end function plotly_apply_aspect_ratio(sp::Subplot, plotarea, pcts) - aspect_ratio = sp[:aspect_ratio] + aspect_ratio = get_aspect_ratio(sp) if aspect_ratio != :none if aspect_ratio == :equal aspect_ratio = 1.0 diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 19137b13..dc584e0d 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1155,7 +1155,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) end # aspect ratio - aratio = sp[:aspect_ratio] + aratio = get_aspect_ratio(sp) if aratio != :none ax."set_aspect"(isa(aratio, Symbol) ? string(aratio) : aratio, anchor = "C") end diff --git a/src/series.jl b/src/series.jl index 6726de71..bba2f313 100644 --- a/src/series.jl +++ b/src/series.jl @@ -347,6 +347,7 @@ end seriestype := :heatmap yflip --> true cbar --> false + aspect_ratio --> :equal z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat) SliceIt, m, n, Surface(z) end diff --git a/src/utils.jl b/src/utils.jl index 34099584..ef15b8b5 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -116,24 +116,11 @@ end function replace_image_with_heatmap(z::Array{T}) where T<:Colorant n, m = size(z) - # idx = 0 colors = ColorGradient(vec(z)) newz = reshape(range(0, stop=1, length=n*m), n, m) newz, colors - # newz = zeros(n, m) - # for i=1:n, j=1:m - # push!(colors, T(z[i,j]...)) - # newz[i,j] = idx / (n*m-1) - # idx += 1 - # end - # newz, ColorGradient(colors) end -function imageHack(plotattributes::AKW) - is_seriestype_supported(:heatmap) || error("Neither :image or :heatmap are supported!") - plotattributes[:seriestype] = :heatmap - plotattributes[:z], plotattributes[:fillcolor] = replace_image_with_heatmap(plotattributes[:z].surf) -end # --------------------------------------------------------------- "Build line segments for plotting" @@ -710,6 +697,19 @@ function has_attribute_segments(series::Series) return any((typeof(series[attr]) <: AbstractVector && length(series[attr]) > 1) for attr in [:seriescolor, :seriesalpha, :linecolor, :linealpha, :linewidth, :linestyle, :fillcolor, :fillalpha, :markercolor, :markeralpha, :markerstrokecolor, :markerstrokealpha]) || any(typeof(series[attr]) <: AbstractArray for attr in (:line_z, :fill_z, :marker_z)) end +function get_aspect_ratio(sp) + aspect_ratio = sp[:aspect_ratio] + if aspect_ratio == :auto + aspect_ratio = :none + for series in series_list(sp) + if series[:seriestype] == :image + aspect_ratio = :equal + end + end + end + return aspect_ratio +end + # --------------------------------------------------------------- makekw(; kw...) = KW(kw)