Different figure object when using PlotlyJS.make_subplots()

Today it gave me a headache to understand the different behaviour of Plot() and make_subplots() of the package PlotlyJS.
Below an example that shows the difference and might help others:

using PlotlyJS
# ---
function plot_two_column_five_raws()
    # Here is an example that uses the `rowspan` and `colspan` subplot options
    # to create a custom subplot layout with subplots of mixed sizes.
    _fig_obj = PlotlyJS.make_subplots(
        rows=5, cols=2,
        #         column 1                     column 2
        specs = [ Spec()                       Spec(rowspan=2) # raw 1
                  Spec()                       missing         # raw 2
                  Spec(rowspan=2, colspan=2)   missing         # raw 3
                  missing                      missing         # raw 4
                  Spec()                       Spec()]         # raw 5
    )

    PlotlyJS.add_trace!(_fig_obj, scatter(x=[1, 2], y=[1, 2], name="(1,1)"), row=1, col=1)
    PlotlyJS.add_trace!(_fig_obj, scatter(x=[1, 2], y=[1, 2], name="(1,2)"), row=1, col=2)
    PlotlyJS.add_trace!(_fig_obj, scatter(x=[1, 2], y=[1, 2], name="(2,1)"), row=2, col=1)
    PlotlyJS.add_trace!(_fig_obj, scatter(x=[1, 2], y=[1, 2], name="(3,1)"), row=3, col=1)
    PlotlyJS.add_trace!(_fig_obj, scatter(x=[1, 2], y=[1, 2], name="(5,1)"), row=5, col=1)
    PlotlyJS.add_trace!(_fig_obj, scatter(x=[1, 2], y=[1, 2], name="(5,2)"), row=5, col=2)

    PlotlyJS.relayout!(_fig_obj, height=600, width=600, title_text = "specs examples", ) 
    # PlotlyJS.relayout!(_fig_obj, height=600, width=600, title_text = "specs examples", xaxis_title_text = "x-Axis", )
    # --- figure object created by PlotlyJS.make_subplots() produces a different plot object, that holds the field "plot"
    plt_layout = PlotlyJS.Layout(; xaxis_title_text = "x-Axis", )
    PlotlyJS.relayout!(_fig_obj.plot, plt_layout) # instead the figure object, we modify only the field ".plot"
    return _fig_obj
end

# --- displays output in separate electron-window
plot_two_column_five_raws() 
# --- displays output inside VScode or in a web-browser
plot_two_column_five_raws().plot
1 Like