Changing axis properties after plotting

I’m wondering if there is a way to change the axis properties after plotting. For example,

using CairoMakie

fig = Figure()
fig[1,1] = Axis(fig)
xs = range(0, 2π, 100)
lines!(xs, sin.(xs))
# Want something like the following:
# xticks!(fig, MultiplesTicks(5,π,"π"))
display(fig)

I have a function plot_data() that plots data and returns the plotted Figure. The figure has several Axis’s, and different axes have different axes properties. I could pass multiple sets keyword arguments to plot_data() to control the behaviors of the individual axes, but it would make the argument list of plot_data() too long. If we can access the axes of the figure returned from plot_data() and change their properties, I won’t need to pass a bulky list of Axis keyword arguments to plot_data().

f = Figure()
for i in 1:3, j in 1:3
    Axis(f[i, j], title = "$i, $j")
end

# pretend you get f here and want to change Axes you can't directly get as variables

ax = f.content[3]
ax.subtitle = "f.content[3]"

ax2 = content(f.layout[2, 1])
ax2.subtitle = "content(f.layout[2, 1])"

f

2 Likes

Thanks! Following your example, here is the version of my example achieving what I want:

using CairoMakie

fig = Figure()
fig[1,1] = Axis(fig)
xs = range(0, 2π, 100)
lines!(xs, sin.(xs))
ax = content(fig.layout[1,1])
ax.xticks = MultiplesTicks(5,π,"π")

display(fig)

Ah you can also do f[1, 1] that’s the same as f.layout[1, 1]