Skip to content

Commit f54c59b

Browse files
InfiniteChait-bltg
andauthored
skip annotations for plot title subplot (#5104)
Co-authored-by: t-bltg <tf.bltg@gmail.com>
1 parent ba325c3 commit f54c59b

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

PlotsBase/src/Plots.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ function _update_subplot_attrs(
247247

248248
# grab those args which apply to this subplot
249249
for k keys(_subplot_defaults)
250+
# We don't apply annotations to the plot-title sub-plot
251+
if k == :annotations && get(plt.attr, :plot_titleindex, 0) == subplot_index
252+
continue
253+
end
250254
PlotsBase.slice_arg!(plotattributes_in, sp.attr, k, subplot_index, remove_pair)
251255
end
252256

PlotsBase/test/test_components.jl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,66 @@ end
187187
annotate!(pl, loc, string(loc))
188188
end
189189
end
190+
191+
let p = scatter([4], [4], plot_title = "x", xlims = (0, 10), ylims = (0, 10))
192+
for sp p.subplots
193+
@test sp[:annotations] == []
194+
end
195+
annotate!(4, 4, "4")
196+
197+
for (i, sp) enumerate(p.subplots)
198+
if i == p.attr[:plot_titleindex]
199+
@test sp[:annotations] == []
200+
else
201+
@test length(sp[:annotations]) == 1
202+
@test sp[:annotations][1][1] == 4
203+
@test sp[:annotations][1][2] == 4
204+
@test sp[:annotations][1][3].str == "4"
205+
end
206+
end
207+
end
208+
209+
let p = scatter(
210+
[4],
211+
[4],
212+
plot_title = "x",
213+
xlims = (0, 10),
214+
ylims = (0, 10),
215+
annotations = (4, 4, "4"),
216+
)
217+
for (i, sp) enumerate(p.subplots)
218+
if i == p.attr[:plot_titleindex]
219+
@test sp[:annotations] == []
220+
else
221+
@test length(sp[:annotations]) == 1
222+
@test sp[:annotations][1][1] == 4
223+
@test sp[:annotations][1][2] == 4
224+
@test sp[:annotations][1][3].str == "4"
225+
end
226+
end
227+
end
228+
229+
let p = plot(
230+
scatter([4], [4], xlims = (0, 10), ylims = (0, 10)),
231+
scatter([4], [4], xlims = (0, 10), ylims = (0, 10)),
232+
plot_title = "x",
233+
)
234+
for sp p.subplots
235+
@test sp[:annotations] == []
236+
end
237+
annotate!(4, 4, "4")
238+
239+
for (i, sp) enumerate(p.subplots)
240+
if i == p.attr[:plot_titleindex]
241+
@test sp[:annotations] == []
242+
else
243+
@test length(sp[:annotations]) == 1
244+
@test sp[:annotations][1][1] == 4
245+
@test sp[:annotations][1][2] == 4
246+
@test sp[:annotations][1][3].str == "4"
247+
end
248+
end
249+
end
190250
end
191251

192252
@testset "Fonts" begin

0 commit comments

Comments
 (0)