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

Commit 83ce8be

Browse files
authored
add delete and empty for axis and delete for lscene (#679)
1 parent bd17df7 commit 83ce8be

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

docs/src/makielayout/axis.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,30 @@ scatobject = scatter!(0:0.5:10, cos, color = :orange)
3636
f
3737
```
3838

39+
## Deleting plots
40+
41+
You can delete a plot object directly via `delete!(ax, plotobj)`.
42+
You can also remove all plots with `empty!(ax)`.
43+
44+
```@example
45+
using CairoMakie
46+
CairoMakie.activate!() # hide
47+
AbstractPlotting.inline!(true) # hide
48+
49+
f = Figure(resolution = (1200, 500))
50+
51+
axs = [Axis(f[1, i]) for i in 1:3]
52+
53+
scatters = map(axs) do ax
54+
[scatter!(ax, 0:0.1:10, x -> sin(x) + i) for i in 1:3]
55+
end
56+
57+
delete!(axs[2], scatters[2][2])
58+
empty!(axs[3])
59+
60+
f
61+
```
62+
3963

4064
## Setting Axis limits and reversing axes
4165

@@ -596,4 +620,5 @@ scene
596620
```@eval
597621
using GLMakie
598622
GLMakie.activate!()
599-
```
623+
```
624+

src/makielayout/layoutables/axis.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,4 +989,16 @@ end
989989

990990
function limits!(args...)
991991
limits!(current_axis(), args...)
992-
end
992+
end
993+
994+
function Base.delete!(ax::Axis, plot::AbstractPlot)
995+
delete!(ax.scene, plot)
996+
ax
997+
end
998+
999+
function Base.empty!(ax::Axis)
1000+
for plot in copy(ax.scene.plots)
1001+
delete!(ax, plot)
1002+
end
1003+
ax
1004+
end

src/makielayout/layoutables/scene.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ function layoutable(::Type{LScene}, fig_or_scene; bbox = nothing, scenekw = Name
4343

4444
ls
4545
end
46+
47+
function Base.delete!(ax::LScene, plot::AbstractPlot)
48+
delete!(ax.scene, plot)
49+
ax
50+
end

test/unit_tests/makielayout.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,18 @@
1616
tb = layout[end + 1, :] = Textbox(scene)
1717
is = layout[end + 1, :] = IntervalSlider(scene)
1818
@test true
19+
end
20+
21+
@testset "deleting from axis" begin
22+
f = Figure()
23+
ax = Axis(f[1, 1])
24+
sc = scatter!(ax, randn(100, 2))
25+
li = lines!(ax, randn(100, 2))
26+
hm = heatmap!(ax, randn(20, 20))
27+
@test length(ax.scene.plots) == 3
28+
delete!(ax, sc)
29+
@test length(ax.scene.plots) == 2
30+
@test sc ax.scene.plots
31+
empty!(ax)
32+
@test isempty(ax.scene.plots)
1933
end

0 commit comments

Comments
 (0)