# Makie: Combine plots into subplots

**URL:** https://discourse.julialang.org/t/makie-combine-plots-into-subplots/62280
**Category:** General Usage
**Tags:** question, plotting, makie
**Created:** [June 2, 2021, 3:32pm UTC](https://discourse.julialang.org/t/makie-combine-plots-into-subplots/62280 "2021-06-02T15:32:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)
#### Post date: [June 2, 2021, 3:32pm UTC](https://discourse.julialang.org/t/makie-combine-plots-into-subplots/62280/1 "2021-06-02T15:32:51Z")

</div>

In Plots.jl, I can make a plot and then use it either as a stand-alone figure or as a subplot:

```julia
using Plots

myplot(n) = plot(1 : n; xlabel = "x")

f1 = myplot(10);
f2 = myplot(20);
fig = plot(f1, f2);

```

Can I do something similar in Makie.jl?

I can, of course, define

```julia
function myplot(n)
  fig = Figure();
  ax = fig[1,1] = Axis(fig; xlabel = "x");
  myplot!(ax, n);
  return fig
end

function myplot!(ax, n)
  lines!(ax, 1:n);
end

```

But I am hoping for a less verbose solution where I don’t have to define two functions for each type of plot that I want to generate. How can I do this?

---

<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: [June 2, 2021, 4:22pm UTC](https://discourse.julialang.org/t/makie-combine-plots-into-subplots/62280/2 "2021-06-02T16:22:45Z")

</div>

Is it a plot like a combination of basic plot types? If so, use the recipe macro to define a new recipe which will have all the axis and figure generating convenience methods. Or is this supposed to be something that generates multiple subplots already?

---

<div class="post-metadata">

### Author: ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)
#### Post date: [June 2, 2021, 4:43pm UTC](https://discourse.julialang.org/t/makie-combine-plots-into-subplots/62280/3 "2021-06-02T16:43:01Z")

</div>

They are not basic plots. To give context, I simulate a model and report statistics that are grouped in certain ways.  
So I have a function that plots a statistic grouped by, say, (:a, :b). There are customizations that are specific to (:a, :b).  
This is called in various places and sometimes combined into subplots and sometimes not.

Thank you.

---

<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: [June 2, 2021, 5:19pm UTC](https://discourse.julialang.org/t/makie-combine-plots-into-subplots/62280/4 "2021-06-02T17:19:51Z")

</div>

What I often do currently, because we don’t have subplot level recipes yet, is to make a function that receives either a Figure or a FigurePosition. If there’s no input argument, a new figure is created. This then works for both the single figure and subplot case.

```julia
function myplot(f = Figure())
    Axis(f[1, 1])
    Colorbar(f[1, 2])
    f
end

myplot()
myplot(some_figure[1:2, 3])

```

---

<div class="post-metadata">

### Author: ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)
#### Post date: [June 2, 2021, 6:51pm UTC](https://discourse.julialang.org/t/makie-combine-plots-into-subplots/62280/5 "2021-06-02T18:51:31Z")

</div>

Thank you - this is helpful. I have to play around with this for a bit to really understand the syntax, but I will close this for now.
