diff --git a/src/layouts.jl b/src/layouts.jl index 6f0548de5..62559427d 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -455,9 +455,9 @@ end function layout_args(plotattributes::AKW, n_override::Integer) layout, n = layout_args(n_override, get(plotattributes, :layout, n_override)) - if n != n_override + if n < n_override error( - "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.", + "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.", ) end layout, n diff --git a/test/test_layouts.jl b/test/test_layouts.jl index d5d5cceec..151492dfd 100644 --- a/test/test_layouts.jl +++ b/test/test_layouts.jl @@ -33,6 +33,26 @@ end @test p[3][:framestyle] === :none end +@testset "Allowed subplot counts" begin + p = plot(plot(1:2); layout = grid(2, 2)) + @test length(p) == 1 + p = plot(plot(1:2), plot(1:2); layout = grid(2, 2)) + @test length(p) == 2 + p = plot(plot(1:2), plot(1:2), plot(1:2); layout = grid(2, 2)) + @test length(p) == 3 + @test length(plot!(p, plot(1:2))) == 4 + p = plot(plot(1:2), plot(1:2), plot(1:2), plot(1:2); layout = grid(2, 2)) + @test length(p) == 4 + @test_throws ErrorException plot( + plot(1:2), + plot(1:2), + plot(1:2), + plot(1:2), + plot(1:2); + layout = grid(2, 2), + ) +end + @testset "Coverage" begin p = plot((plot(i) for i in 1:4)..., layout = (2, 2))