From bf5d1aa06064ef60c01974e89d591f8bbfe30a35 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Mon, 7 Feb 2022 21:21:22 +0100 Subject: [PATCH] Fix `plotattributes` in `_add_plot_title!` (#4090) Co-authored-by: Simon Christ --- src/args.jl | 2 +- src/pipeline.jl | 3 ++- src/plot.jl | 4 ++-- test/runtests.jl | 32 +++++++++++++++++++------------- test/test_layouts.jl | 7 +++++++ 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/args.jl b/src/args.jl index 759234368..e72241210 100644 --- a/src/args.jl +++ b/src/args.jl @@ -2059,7 +2059,7 @@ function _update_subplot_args( ) anns = RecipesPipeline.pop_kw!(sp.attr, :annotations) - # # grab those args which apply to this subplot + # grab those args which apply to this subplot for k in keys(_subplot_defaults) slice_arg!(plotattributes_in, sp.attr, k, subplot_index, remove_pair) end diff --git a/src/pipeline.jl b/src/pipeline.jl index 7808f7b61..7874543db 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -289,6 +289,7 @@ end function _add_plot_title!(plt) plot_title = plt[:plot_title] + plot_titleindex = nothing if plot_title != "" # make new subplot for plot title @@ -319,7 +320,7 @@ function _add_plot_title!(plt) end end - return nothing + return plot_titleindex end ## Series recipes diff --git a/src/plot.jl b/src/plot.jl index ba689a0b5..3fa4d0445 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -163,11 +163,11 @@ function plot!(plt1::Plot, plt2::Plot, plts_tail::Plot...; kw...) cmdidx += 1 end end - _add_plot_title!(plt) + ttl_idx = _add_plot_title!(plt) # first apply any args for the subplots for (idx, sp) in enumerate(plt.subplots) - _update_subplot_args(plt, sp, plotattributes, idx, false) + _update_subplot_args(plt, sp, idx == ttl_idx ? KW() : plotattributes, idx, false) end # finish up diff --git a/test/runtests.jl b/test/runtests.jl index 66885cffd..a5e1cf61f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -37,19 +37,25 @@ end Plots.use_local_dependencies[] = temp end -include("test_defaults.jl") -include("test_pipeline.jl") -include("test_axes.jl") -include("test_layouts.jl") -include("test_contours.jl") -include("test_axis_letter.jl") -include("test_components.jl") -include("test_shorthands.jl") -include("integration_dates.jl") -include("test_recipes.jl") -include("test_hdf5plots.jl") -include("test_pgfplotsx.jl") -include("test_plotly.jl") +for fn in ( + "test_defaults.jl", + "test_pipeline.jl", + "test_axes.jl", + "test_layouts.jl", + "test_contours.jl", + "test_axis_letter.jl", + "test_components.jl", + "test_shorthands.jl", + "integration_dates.jl", + "test_recipes.jl", + "test_hdf5plots.jl", + "test_pgfplotsx.jl", + "test_plotly.jl", +) + @testset "$fn" begin + include(fn) + end +end reference_dir(args...) = joinpath(homedir(), ".julia", "dev", "PlotReferenceImages", args...) diff --git a/test/test_layouts.jl b/test/test_layouts.jl index 41ce0bdf3..90cf2ba86 100644 --- a/test/test_layouts.jl +++ b/test/test_layouts.jl @@ -25,3 +25,10 @@ end @test pl[:plot_title] == "My new title" @test pl[:plot_titleindex] == 5 end + +@testset "Plots.jl/issues/4083" begin + p = plot(plot(1:2), plot(1:2); border = :grid, plot_title = "abc") + @test p[1][:framestyle] === :grid + @test p[2][:framestyle] === :grid + @test p[3][:framestyle] === :none +end