Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
add delete and empty for axis and delete for lscene (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel authored Mar 29, 2021
1 parent bd17df7 commit 83ce8be
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
27 changes: 26 additions & 1 deletion docs/src/makielayout/axis.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ scatobject = scatter!(0:0.5:10, cos, color = :orange)
f
```

## Deleting plots

You can delete a plot object directly via `delete!(ax, plotobj)`.
You can also remove all plots with `empty!(ax)`.

```@example
using CairoMakie
CairoMakie.activate!() # hide
AbstractPlotting.inline!(true) # hide
f = Figure(resolution = (1200, 500))
axs = [Axis(f[1, i]) for i in 1:3]
scatters = map(axs) do ax
[scatter!(ax, 0:0.1:10, x -> sin(x) + i) for i in 1:3]
end
delete!(axs[2], scatters[2][2])
empty!(axs[3])
f
```


## Setting Axis limits and reversing axes

Expand Down Expand Up @@ -596,4 +620,5 @@ scene
```@eval
using GLMakie
GLMakie.activate!()
```
```

14 changes: 13 additions & 1 deletion src/makielayout/layoutables/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -989,4 +989,16 @@ end

function limits!(args...)
limits!(current_axis(), args...)
end
end

function Base.delete!(ax::Axis, plot::AbstractPlot)
delete!(ax.scene, plot)
ax
end

function Base.empty!(ax::Axis)
for plot in copy(ax.scene.plots)
delete!(ax, plot)
end
ax
end
5 changes: 5 additions & 0 deletions src/makielayout/layoutables/scene.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ function layoutable(::Type{LScene}, fig_or_scene; bbox = nothing, scenekw = Name

ls
end

function Base.delete!(ax::LScene, plot::AbstractPlot)
delete!(ax.scene, plot)
ax
end
14 changes: 14 additions & 0 deletions test/unit_tests/makielayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@
tb = layout[end + 1, :] = Textbox(scene)
is = layout[end + 1, :] = IntervalSlider(scene)
@test true
end

@testset "deleting from axis" begin
f = Figure()
ax = Axis(f[1, 1])
sc = scatter!(ax, randn(100, 2))
li = lines!(ax, randn(100, 2))
hm = heatmap!(ax, randn(20, 20))
@test length(ax.scene.plots) == 3
delete!(ax, sc)
@test length(ax.scene.plots) == 2
@test sc ax.scene.plots
empty!(ax)
@test isempty(ax.scene.plots)
end

0 comments on commit 83ce8be

Please sign in to comment.