Skip to content

Commit 03d015c

Browse files
Make layouts tolerant of having too-few items (#4247)
* Make layouts tolerant of fewer items. * Add tests * Remove grid kwarg * format add `plot!` test Co-authored-by: Simon Christ <christ@cell.uni-hannover.de>
1 parent 772cd51 commit 03d015c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/layouts.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ end
455455

456456
function layout_args(plotattributes::AKW, n_override::Integer)
457457
layout, n = layout_args(n_override, get(plotattributes, :layout, n_override))
458-
if n != n_override
458+
if n < n_override
459459
error(
460-
"When doing layout, n ($n) != n_override ($(n_override)). You're probably trying to force existing plots into a layout that doesn't fit them.",
460+
"When doing layout, n ($n) < n_override ($(n_override)). You're probably trying to force existing plots into a layout that doesn't fit them.",
461461
)
462462
end
463463
layout, n

test/test_layouts.jl

+20
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ end
3333
@test p[3][:framestyle] === :none
3434
end
3535

36+
@testset "Allowed subplot counts" begin
37+
p = plot(plot(1:2); layout = grid(2, 2))
38+
@test length(p) == 1
39+
p = plot(plot(1:2), plot(1:2); layout = grid(2, 2))
40+
@test length(p) == 2
41+
p = plot(plot(1:2), plot(1:2), plot(1:2); layout = grid(2, 2))
42+
@test length(p) == 3
43+
@test length(plot!(p, plot(1:2))) == 4
44+
p = plot(plot(1:2), plot(1:2), plot(1:2), plot(1:2); layout = grid(2, 2))
45+
@test length(p) == 4
46+
@test_throws ErrorException plot(
47+
plot(1:2),
48+
plot(1:2),
49+
plot(1:2),
50+
plot(1:2),
51+
plot(1:2);
52+
layout = grid(2, 2),
53+
)
54+
end
55+
3656
@testset "Coverage" begin
3757
p = plot((plot(i) for i in 1:4)..., layout = (2, 2))
3858

0 commit comments

Comments
 (0)