Floating subplot in Plots recipe?

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


Currently, this works by having three subplots stacked vertically. Here is the relevant code in the recipe:

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

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

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

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

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

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

2 Likes