From 7d26ba527b1bd7293a7b2d1d275bd845a8e973b7 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 4 Feb 2022 18:01:24 +0100 Subject: [PATCH 1/2] aspect ratio 3d --- src/axes.jl | 64 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index f2298292..e26e3b8d 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -642,31 +642,55 @@ function axis_limits( !has_user_lims && consider_aspect && letter in (:x, :y) && - !(sp[:aspect_ratio] in (:none, :auto) || RecipesPipeline.is3d(:sp)) + sp[:aspect_ratio] in (:none, :auto) ) - aspect_ratio = isa(sp[:aspect_ratio], Number) ? sp[:aspect_ratio] : 1 - plot_ratio = height(plotarea(sp)) / width(plotarea(sp)) - dist = amax - amin + if !RecipesPipeline.is3d(:sp) + aspect_ratio = isa(sp[:aspect_ratio], Number) ? sp[:aspect_ratio] : 1 + plot_ratio = height(plotarea(sp)) / width(plotarea(sp)) + dist = amax - amin - if letter == :x - yamin, yamax = axis_limits(sp, :y, default_should_widen(sp[:yaxis]), false) - ydist = yamax - yamin - axis_ratio = aspect_ratio * ydist / dist - factor = axis_ratio / plot_ratio + if letter == :x + yamin, yamax = axis_limits(sp, :y, default_should_widen(sp[:yaxis]), false) + ydist = yamax - yamin + axis_ratio = aspect_ratio * ydist / dist + factor = axis_ratio / plot_ratio + else + xamin, xamax = axis_limits(sp, :x, default_should_widen(sp[:xaxis]), false) + xdist = xamax - xamin + axis_ratio = aspect_ratio * dist / xdist + factor = plot_ratio / axis_ratio + end + + if factor > 1 + center = (amin + amax) / 2 + amin = center + factor * (amin - center) + amax = center + factor * (amax - center) + end else - xamin, xamax = axis_limits(sp, :x, default_should_widen(sp[:xaxis]), false) - xdist = xamax - xamin - axis_ratio = aspect_ratio * dist / xdist - factor = plot_ratio / axis_ratio - end - - if factor > 1 - center = (amin + amax) / 2 - amin = center + factor * (amin - center) - amax = center + factor * (amax - center) end end - + if RecipesPipeline.is3d(:sp) + xs = sp[1][:x] + ys = sp[1][:y] + zs = sp[1][:z] + x12, y12, z12 = extrema(xs), extrema(ys), extrema(zs) + d = maximum([diff([x12...]),diff([y12...]),diff([z12...])])[1] / 2 + xm, ym, zm = mean(x12), mean(y12), mean(z12) + amin = if letter == :x + xm-d + elseif letter == :y + ym-d + elseif letter ==:z + zm-d + end + amax = if letter == :x + xm+d + elseif letter == :y + ym+d + elseif letter ==:z + zm+d + end + end return amin, amax end From f8f02ce02b5533fb63c06f39327649412200f72d Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Tue, 22 Mar 2022 11:45:40 +0100 Subject: [PATCH 2/2] generalize on multiple series --- src/axes.jl | 28 ++++++++++------------------ src/types.jl | 1 + 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index e26e3b8d..17897f07 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -669,26 +669,18 @@ function axis_limits( else end end - if RecipesPipeline.is3d(:sp) - xs = sp[1][:x] - ys = sp[1][:y] - zs = sp[1][:z] - x12, y12, z12 = extrema(xs), extrema(ys), extrema(zs) - d = maximum([diff([x12...]),diff([y12...]),diff([z12...])])[1] / 2 - xm, ym, zm = mean(x12), mean(y12), mean(z12) - amin = if letter == :x - xm-d + if RecipesPipeline.is3d(:sp) && consider_aspect == true + x12, y12, z12 = extrema(sp, :x), extrema(sp, :y), extrema(sp, :z) + d = maximum((x12[2] - x12[1], y12[2] - y12[1], z12[2] - z12[1])) / 2 + amin, amax = if letter == :x + xm = mean(x12) + xm-d, xm+d elseif letter == :y - ym-d + ym = mean(y12) + ym-d, ym+d elseif letter ==:z - zm-d - end - amax = if letter == :x - xm+d - elseif letter == :y - ym+d - elseif letter ==:z - zm+d + zm = mean(z12) + zm-d, zm+d end end return amin, amax diff --git a/src/types.jl b/src/types.jl index 24d441a2..c319835e 100644 --- a/src/types.jl +++ b/src/types.jl @@ -43,6 +43,7 @@ mutable struct Subplot{T<:AbstractBackend} <: AbstractLayout end Base.show(io::IO, sp::Subplot) = print(io, "Subplot{$(sp[:subplot_index])}") +Base.extrema(sp::Subplot, letter::Symbol) = minimum(minimum.(getindex.(sp.series_list, letter))), maximum(maximum.(getindex.(sp.series_list, letter))) # -----------------------------------------------------------