From 345f5654a3235f51d64971f00fdc2fb18d6fd218 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 1 Mar 2020 01:37:34 +0100 Subject: [PATCH 1/3] use equal aspect ratio by default for images --- src/args.jl | 2 +- src/backends/gr.jl | 2 +- src/backends/pgfplots.jl | 2 +- src/backends/plotly.jl | 2 +- src/backends/pyplot.jl | 2 +- src/series.jl | 1 + src/utils.jl | 26 +++++++++++++------------- 7 files changed, 19 insertions(+), 18 deletions(-) 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) From 599d6a2ec8d42470234fc4c50d917dfbe68460e1 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 1 Mar 2020 01:56:46 +0100 Subject: [PATCH 2/3] add commented code to update refernce images --- test/runtests.jl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 1c8e2932..037f7653 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -44,6 +44,30 @@ default(show=false, reuse=true) is_ci() = get(ENV, "CI", "false") == "true" img_tol = is_ci() ? 1e-2 : 1e-3 +## Uncomment the following lines to update reference images for different backends + +#= +@testset "GR" begin + image_comparison_facts(:gr, tol=img_tol, skip = Plots._backend_skips[:gr]) +end + +plotly() +@testset "Plotly" begin + image_comparison_facts(:plotly, tol=img_tol, skip = Plots._backend_skips[:plotlyjs]) +end + +pyplot() +@testset "PyPlot" begin + image_comparison_facts(:pyplot, tol=img_tol, skip = Plots._backend_skips[:pyplot]) +end + +pgfplots() +@testset "PGFPlots" begin + image_comparison_facts(:pgfplots, tol=img_tol, skip = Plots._backend_skips[:pgfplots]) +end +=# +## + @testset "Backends" begin @testset "GR" begin From 8d7b07eab34e3dcdd310f35b072b92aaffad8a39 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 1 Mar 2020 01:57:22 +0100 Subject: [PATCH 3/3] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 46aacdfd..302cb820 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Plots" uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" author = ["Tom Breloff (@tbreloff)"] -version = "0.29.3" +version = "0.29.4" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"