PlotlyJS and subplots: shared yaxis_range

Edited: now, with a MWE that can be replicated

Hi,

I need to create a figure with some subplots, like the following one:

The code I used is this:

using PlotlyJS

p1 = make_subplots(rows=2, cols=2,
    specs=[Spec(colspan=2) missing ; Spec() Spec()],
    subplot_titles=["First subplot"  "Third subplot" ; "Second subplot"  missing],
    vertical_spacing = 0.1, horizontal_spacing = 0.09 )

add_trace!(p1, scatter(x=1:5, y=rand(5)), row=1, col=1)
add_trace!(p1, scatter(x=1:5, y=rand(5)), row=2, col=1)
add_trace!(p1, scatter(x=1:5, y=rand(5)), row=2, col=2)

relayout!(p1, showlegend=true, title_text = "Central bank losses",
height = "800", hovermode = "x" )
p1

I do not know whether forcing the two yaxis_ranges to have the same range is possible. In this case, I need a visual comparison; the same yaxis_ranges are essential.

Another doubt I have is whether it is possible to have different yaxis_titles (or xaxis_titles) in individual subplots (not in this example, but sometimes they are needed for specific purposes).

I did my best to achieve what I needed by looking here and here, and also in some other places. But with no success.

Thanks.

This only works when you want to share all x/y axes in a given subplot row/column, but make_subplots takes kwargs shared_xaxes and shared_yaxes that can be set to "rows", "columns", or "all".

If you need something more complex (e.g. only some of the subplots in a row sharing the same yaxis), you can specify the x/y axis for a trace as a kwarg in the trace constructor (e.g. scatter, etc) as eg yaxis="y2". (I don’t remember off hand which corner/direction axis counting starts.) Higher axis number will create a new one if it doesn’t already exist.