# Floating subplot in Plots recipe?

**URL:** <https://discourse.julialang.org/t/floating-subplot-in-plots-recipe/60441>\
**Category:** General Usage\
**Tags:** plotting, plots, recipe\
**Created:** [May 2, 2021, 10:34pm UTC](https://discourse.julialang.org/t/floating-subplot-in-plots-recipe/60441 "2021-05-02T22:34:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdh62043](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@jdh62043](https://discourse.julialang.org/u/jdh62043)\
**Post date:** [May 2, 2021, 10:34pm UTC](https://discourse.julialang.org/t/floating-subplot-in-plots-recipe/60441/1 "2021-05-02T22:34:42Z")

</div>

I am making a user recipe for Plots to visualize a struct representing a spectrum:

 ![Screenshot_20210502_151208](https://global.discourse-cdn.com/julialang/original/3X/5/4/5401d0b0a736a2c7590902c1858d667791b283d9.png)  
Currently, this works by having three subplots stacked vertically. Here is the relevant code in the recipe:

```julia
    grid := false
    framestyle := [:none :none :axes]
    layout := @layout [sample_swatches{0.1h}
                       sample_swatches{0.1h}
                       spectrum]

```

I was hoping to cut down on the gaps between the two sets of color swatches as they aren’t that important. However, the margin is already at zero. I was thinking another way to accomplish this would be to make them floating subplots inside the main graph, [according to this documentation](https://docs.juliaplots.org/latest/layouts/#Advanced-Layouts). However, the linked page accomplishes this by explicitly generating the subplots with calls to `histogram!` and `sticks!`, providing them a named argument to make them floating.

I was wondering how this technique can be adapted to work in a recipe.

---

<div class="post-metadata">

**Author:** ![jdh62043](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@jdh62043](https://discourse.julialang.org/u/jdh62043)\
**Post date:** [May 3, 2021, 5:43am UTC](https://discourse.julialang.org/t/floating-subplot-in-plots-recipe/60441/2 "2021-05-03T05:43:35Z")

</div>

I mistakenly thought that the margin could not be set for individual subplots. It turns out that doing this:

```julia
margin := [-5mm, -5mm, 5mm]

```

will cause runtime errors, but simply removing the commas like this:

```julia
margin := [-5mm -5mm 5mm]

```

works perfectly, allowing me to crop the two subplots down to size. This is the result:

 ![Screenshot_20210502_224317](https://global.discourse-cdn.com/julialang/original/3X/9/e/9ea885a3eb9946d9a4cd148d55497a410d5cb023.png)
