Skip to content
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

add empty! for Plots and Subplots #4543

Merged
merged 1 commit into from
Nov 23, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,17 @@ Base.size(plt::Plot) = size(plt.layout)
Base.size(plt::Plot, i::Integer) = size(plt.layout)[i]
Base.ndims(plt::Plot) = 2

# clear out series list, but retain subplots
Base.empty!(plt::Plot) = foreach(sp -> empty!(sp.series_list), plt.subplots)

# attr(plt::Plot, k::Symbol) = plt.attr[k]
# attr!(plt::Plot, v, k::Symbol) = (plt.attr[k] = v)

Base.getindex(sp::Subplot, i::Union{Vector{<:Integer},Integer}) = series_list(sp)[i]
Base.lastindex(sp::Subplot) = length(series_list(sp))

Base.empty!(sp::Subplot) = empty!(sp.series_list)

# -----------------------------------------------------------------------

Base.show(io::IO, sp::Subplot) = print(io, "Subplot{$(sp[:subplot_index])}")
Expand Down
16 changes: 15 additions & 1 deletion test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ end
end
end

@testset "plot" begin
@testset "tex_output_standalone" begin
pl = plot(1:5)
pl2 = plot(pl, tex_output_standalone = true)
@test !pl[:tex_output_standalone]
Expand Down Expand Up @@ -191,6 +191,20 @@ end
@test series[:y] == y2
end

@testset "Empty Plot / Subplots" begin
pl = plot(map(_ -> plot(1:2, [1:2 2:3]), 1:2)...)
empty!(pl)
@test length(pl.subplots) == 2
@test length(first(pl).series_list) == 0
@test length(last(pl).series_list) == 0

pl = plot(map(_ -> plot(1:2, [1:2 2:3]), 1:2)...)
empty!(first(pl)) # clear out only the first subplot
@test length(pl.subplots) == 2
@test length(first(pl).series_list) == 0
@test length(last(pl).series_list) == 2
end

@testset "Measures" begin
@test 1Plots.mm * 0.1Plots.pct == 0.1Plots.mm
@test 0.1Plots.pct * 1Plots.mm == 0.1Plots.mm
Expand Down