Inset Plots in Julia

How to make an inset graph in julia.


Simple Inset Plot

You can make an inset plot using the inset argument to make_subplots

This argument expects an array of Inset objects. The Inset object has the following fields:

using PlotlyJS

@doc Inset

Parameters

  • cell: index of the subplot cell to overlay inset axes onto.

  • kind: Subplot kind (see Spec docs)

  • l: padding left of inset in fraction of cell width

  • w: inset width in fraction of cell width ('to_end': to cell right edge)

  • b: padding bottom of inset in fraction of cell height

  • h: inset height in fraction of cell height ('to_end': to cell top edge)

To use make_subplots with inset charts, you first create an empty plot using make_subplots and then add traces to the subplots (including the inset):

using PlotlyJS
p = make_subplots(insets=[Inset(cell=(1,1), l=0.7, b=0.6)]);

# second trace is added to axes (x2, y2), which is the insets
addtraces!(p, scatter(y=rand(10)), scatter(y=1:5, yaxis="y2", xaxis="x2", name="inset"))
p

You can also have inset charts in subplots that are not the first subplot.

Note that inset plots are assigned their "index" after all non inset subplots.

In the example below the top subplot has index (1,1), the bottom subplot has index (2,2) and the inset subplot has index (3,3).

using PlotlyJS
p = make_subplots(insets=[Inset(cell=(2,1), l=0.7, b=0, h=0.5)], rows=2, cols=1);
addtraces!(
    p,
    scatter(y=rand(10), name="top"),
    scatter(y=1:5, yaxis="y2", xaxis="x2", name="bottom"),
    scatter(y=5:-1:1, yaxis="y3", xaxis="x3", name="inset"),
)
p