How to copy a Axis from fig1 to fig2 in makie?

Hi,

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]?

I do some try but failed:

x,y = rand(10), rand(10)
fig1, ax1, p1 = scatter(x,y)
fig2, ax2, p2 = lines(x,y)
fig2[1,2] = ax1

I know it is better to replot ax1 and ax2 in same figure, but I just wonder if there any convenient way to finish this.

thanks for any suggestion.

See no way to do this apart from using “the same figure.”

function discourse92716()
    x, y = rand(10), rand(10)
    fig1 = Figure()
    scatter(fig1[1, 1], x, y)
    fig2 = Figure()
    lines(fig2[1, 1], x, y)
    scatter(fig2[1, 2], x, y)
    # fig2[1, 2] = contents(fig1[1, 1])
    return fig2
end

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].

1 Like

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.

2 Likes