diff --git a/PlotsBase/src/Plots.jl b/PlotsBase/src/Plots.jl index cf440823c..0441616e3 100644 --- a/PlotsBase/src/Plots.jl +++ b/PlotsBase/src/Plots.jl @@ -247,6 +247,10 @@ function _update_subplot_attrs( # grab those args which apply to this subplot for k ∈ keys(_subplot_defaults) + # We don't apply annotations to the plot-title sub-plot + if k == :annotations && get(plt.attr, :plot_titleindex, 0) == subplot_index + continue + end PlotsBase.slice_arg!(plotattributes_in, sp.attr, k, subplot_index, remove_pair) end diff --git a/PlotsBase/test/test_components.jl b/PlotsBase/test/test_components.jl index 740ea053e..02d26d57f 100644 --- a/PlotsBase/test/test_components.jl +++ b/PlotsBase/test/test_components.jl @@ -187,6 +187,66 @@ end annotate!(pl, loc, string(loc)) end end + + let p = scatter([4], [4], plot_title = "x", xlims = (0, 10), ylims = (0, 10)) + for sp ∈ p.subplots + @test sp[:annotations] == [] + end + annotate!(4, 4, "4") + + for (i, sp) ∈ enumerate(p.subplots) + if i == p.attr[:plot_titleindex] + @test sp[:annotations] == [] + else + @test length(sp[:annotations]) == 1 + @test sp[:annotations][1][1] == 4 + @test sp[:annotations][1][2] == 4 + @test sp[:annotations][1][3].str == "4" + end + end + end + + let p = scatter( + [4], + [4], + plot_title = "x", + xlims = (0, 10), + ylims = (0, 10), + annotations = (4, 4, "4"), + ) + for (i, sp) ∈ enumerate(p.subplots) + if i == p.attr[:plot_titleindex] + @test sp[:annotations] == [] + else + @test length(sp[:annotations]) == 1 + @test sp[:annotations][1][1] == 4 + @test sp[:annotations][1][2] == 4 + @test sp[:annotations][1][3].str == "4" + end + end + end + + let p = plot( + scatter([4], [4], xlims = (0, 10), ylims = (0, 10)), + scatter([4], [4], xlims = (0, 10), ylims = (0, 10)), + plot_title = "x", + ) + for sp ∈ p.subplots + @test sp[:annotations] == [] + end + annotate!(4, 4, "4") + + for (i, sp) ∈ enumerate(p.subplots) + if i == p.attr[:plot_titleindex] + @test sp[:annotations] == [] + else + @test length(sp[:annotations]) == 1 + @test sp[:annotations][1][1] == 4 + @test sp[:annotations][1][2] == 4 + @test sp[:annotations][1][3].str == "4" + end + end + end end @testset "Fonts" begin