Skip to content

skip annotations for plot title subplot #5104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions PlotsBase/src/Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
60 changes: 60 additions & 0 deletions PlotsBase/test/test_components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading