From 29475890b28a15362a1d716d8e6687d71f37da65 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Fri, 25 Jun 2021 15:19:06 +0200 Subject: [PATCH] add mwe as example - fix needs_3d_axes --- src/backends/gr.jl | 16 +++++++-------- src/examples.jl | 50 ++++++++++++++++++++++++++++++++++++++++++++++ src/pipeline.jl | 8 ++++++++ 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index f43e791c..87be69bd 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1282,8 +1282,8 @@ function gr_set_window(sp, viewport_plotarea) gr_set_viewport_polar(viewport_plotarea) else xmin, xmax, ymin, ymax = gr_xy_axislims(sp) - is3d = RecipesPipeline.is3d(sp) - if is3d + needs_3d = needs_any_3d_axes(sp) + if needs_3d zmin, zmax = gr_z_axislims(sp) zok = zmax > zmin else @@ -1292,12 +1292,12 @@ function gr_set_window(sp, viewport_plotarea) scaleop = 0 if xmax > xmin && ymax > ymin && zok - sp[:xaxis][:scale] == :log10 && (scaleop |= GR.OPTION_X_LOG) - sp[:yaxis][:scale] == :log10 && (scaleop |= GR.OPTION_Y_LOG) - is3d && sp[:zaxis][:scale] == :log10 && (scaleop |= GR.OPTION_Z_LOG) - sp[:xaxis][:flip] && (scaleop |= GR.OPTION_FLIP_X) - sp[:yaxis][:flip] && (scaleop |= GR.OPTION_FLIP_Y) - is3d && sp[:zaxis][:flip] && (scaleop |= GR.OPTION_FLIP_Z) + sp[:xaxis][:scale] == :log10 && (scaleop |= GR.OPTION_X_LOG) + sp[:yaxis][:scale] == :log10 && (scaleop |= GR.OPTION_Y_LOG) + needs_3d && sp[:zaxis][:scale] == :log10 && (scaleop |= GR.OPTION_Z_LOG) + sp[:xaxis][:flip] && (scaleop |= GR.OPTION_FLIP_X) + sp[:yaxis][:flip] && (scaleop |= GR.OPTION_FLIP_Y) + needs_3d && sp[:zaxis][:flip] && (scaleop |= GR.OPTION_FLIP_Z) # NOTE: setwindow sets the "data coordinate" limits of the current "viewport" GR.setwindow(xmin, xmax, ymin, ymax) GR.setscale(scaleop) diff --git a/src/examples.jl b/src/examples.jl index 6d4e631d..ea1d233f 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -1163,6 +1163,56 @@ const _examples = PlotExample[ ), ], ), + PlotExample( # 55 + "3D axis flip / mirror", + "", + [ + :( + begin + meshgrid(x, y) = (ones(eltype(y), length(y)) * x', y * ones(eltype(x), length(x))') + scalefontsizes(.5) + + x, y = meshgrid(-6:0.5:10, -8:0.5:8) + r = sqrt.(x .^ 2 + y .^ 2) .+ eps() + z = sin.(r) ./ r + + args = x[1, :], y[:, 1], z[:] + kwargs = Dict( + :xlabel => "x", :ylabel => "y", :zlabel => "z", + :grid => true, :minorgrid => true, :dpi => 200 + ) + + plots = [wireframe(args..., title = "wire"; kwargs...)] + + for ax ∈ (:x, :y, :z) + push!(plots, wireframe( + args..., + title = "wire-flip-$ax", + xflip = ax == :x, + yflip = ax == :y, + zflip = ax == :z; + kwargs..., + )) + end + + for ax ∈ (:x, :y, :z) + push!(plots, wireframe( + args..., + title = "wire-mirror-$ax", + xmirror = ax == :x, + ymirror = ax == :y, + zmirror = ax == :z; + kwargs..., + )) + end + + plot(plots..., layout=(@layout [_ ° _; ° ° °; ° ° °]), margin=2Plots.mm) + + scalefontsizes() + end + ), + ], + ), ] # Some constants for PlotDocs and PlotReferenceImages diff --git a/src/pipeline.jl b/src/pipeline.jl index d87c5836..94fce068 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -338,6 +338,14 @@ function _override_seriestype_check(plotattributes::AKW, st::Symbol) st end +function needs_any_3d_axes(sp::Subplot) + any( + RecipesPipeline.needs_3d_axes( + _override_seriestype_check(s.plotattributes, s.plotattributes[:seriestype]) + ) for s in series_list(sp) + ) +end + function _expand_subplot_extrema(sp::Subplot, plotattributes::AKW, st::Symbol) # adjust extrema and discrete info if st == :image