# Storing separate Makie axes from a figure

**URL:** <https://discourse.julialang.org/t/storing-separate-makie-axes-from-a-figure/122620>\
**Category:** General Usage\
**Tags:** makie, cairomakie\
**Created:** [November 14, 2024, 8:48am UTC](https://discourse.julialang.org/t/storing-separate-makie-axes-from-a-figure/122620 "2024-11-14T08:48:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johannesnauta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johannesnauta/32/47434_2.png) [@johannesnauta](https://discourse.julialang.org/u/johannesnauta)\
**Post date:** [November 14, 2024, 8:48am UTC](https://discourse.julialang.org/t/storing-separate-makie-axes-from-a-figure/122620/1 "2024-11-14T08:48:48Z")

</div>

### 1. Storing axes separately

When making figures for publications, I often find myself wanting to store individual axes from a figure with multiple axes. This is to reduce some redundant information, such as shared axis-labels. To illustrate what I mean, consider the following MWE

```julia
using CairoMakie

fig = Figure(; size=(360,400/3), figure_padding=(0,6,2,4))
ax = [Axis(
    fig[1,i], xlabel="x", ylabel="y", aspect=1, limits=(0,1,0,1),
    xlabelsize=10, ylabelsize=10, xticklabelsize=9, yticklabelsize=9,    
    xlabelpadding=1.0, ylabelpadding=3.0,
    ylabelvisible=(i==1), yticklabelsvisible=(i==1)
) for i in 1:3]
for i in 1:3
    scatter!(ax[i], rand(10), rand(10), markersize=5)
end
colgap!(fig.layout, Relative(0.05))
resize_to_layout!(fig)
fig

```

In this snippet, I plot three axes, but only give the first a label on the y-axis and ticklabels are also only visible on the first axis (see fig.).

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/4/04769768407cc2788484668b8360bbeef53b19ff.png)

The problem arises when I want to use other frameworks (mostly TikZ) to make some indications, and/or switch around the location of these plots (e.g., when going through them 1 by one in Beamer).

To achieve this, I thought the easiest solution was to store each axis separately. That is, call something like `save("axis1.pdf", ax[1])`, and thereby only store that specific axis with the appropriate size, etc. However, I do not find any documentation on this kind of behavior. Is there any way to store each axis seperately, while keeping the sizes of the axes as they are in the figure?

### 2. A workaround that does not work: interference of labels

Something I tried was to just make three separate figures, yet in this case the fact that the first axis has y- and ytick-labels makes it very difficult to control the sizes of the figures. The reason is that `Makie` logically tries to fit the size of everything in the given figure size, which includes the labels (if any). So, if there are no labels, the axis itself gets more space and the figures are not of the same size. To avoid this behavior; is there a way to define the size of the axis object instead of the figure? That is, if I make a figure `Figure(; size=(100,100))`, can I specify an axis that has size `(50,50)`, for example?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [November 14, 2024, 9:19am UTC](https://discourse.julialang.org/t/storing-separate-makie-axes-from-a-figure/122620/2 "2024-11-14T09:19:23Z")

</div>

You can do `Axis(..., width = 50, height = 50)` and then to remove the whitespace `resize_to_layout!(fig)`

Also there was this recent thread for saving only a rectangular cropped region of a figure [GLMakie saving Axis - #9 by jules](https://discourse.julialang.org/t/glmakie-saving-axis/122358/9)
