I plot a scatter plot in fig1 position [1,1], then a lines plot in fig2 position [1,1], any idea on how to copy the scatter from fig1[1,1] into fig2[1,2]?
You can try commenting out the scatter call for fig2[1, 2] and uncommenting the contents line. But while this executes without error, it does not show anything at fig2[1, 2].
You can’t currently copy plots or axes from figure to figure. In the future we might make this possible.
Currently, the easiest approach is to just wrap parts that you want to repeat in a function that takes a figure grid position as input, and then you can plot it like myfunction(fig[2, 3]) ec.
Any update on this? Is it still not possible to copy the axis from one figure into another? This could be beneficial in case the plotting function has a long computing time.
It seems that there is not a direct function to copy&paste an axis from another figure in Makie, and I totally understand that is not a critical feature. There are some easy ways to achieve this, like the one suggested by @jules
I prefer to extract the data from a previous figure and then plot it wherever I choose. it’s best to reuse and recreate the plot using the data rather than directly copying and pasting the axis.
here is a toy demo and hope it could help for your case.
"""
get data from an Axis
"""
function getData(ax::Axis)
ax.scene.plots[1].args
end
longTimeToRun(n,m) = rand(n,m)
someComplexProcess(x) = x
fig1 = Figure()
ax = fig1[1,1] |> Axis
scatter!(ax, longTimeToRun(10,2) |> someComplexProcess)
# let's assume that you want to combine the axis into another Figure
# but don't want to wait for longTimeToRun,
# you can just get data from axis and reuse them to plot
fig2 = Figure()
# other code ...
# now you are adding the previous axis
x_y_data = getData( contents(fig1[1,1])[1] )
x, y = x_y_data[1][], x_y_data[2][]
ax2 = fig2[2,1] |> Axis
scatter!(ax2,x,y)
fig2