# PlotlyJS and subplots: shared yaxis\_range

**URL:** <https://discourse.julialang.org/t/plotlyjs-and-subplots-shared-yaxis-range/106238>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [November 14, 2023, 10:52pm UTC](https://discourse.julialang.org/t/plotlyjs-and-subplots-shared-yaxis-range/106238 "2023-11-14T22:52:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VivMendes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vivmendes/32/16477_2.png) [@VivMendes](https://discourse.julialang.org/u/VivMendes)\
**Post date:** [November 14, 2023, 10:52pm UTC](https://discourse.julialang.org/t/plotlyjs-and-subplots-shared-yaxis-range/106238/1 "2023-11-14T22:52:13Z")

</div>

**Edited: now, with a MWE that can be replicated**

Hi,

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

 ![aa](https://global.discourse-cdn.com/julialang/original/3X/0/5/05ca80d78442896f4b5b87b93d7872999bed19e0.png)

The code I used is this:

```julia
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](https://juliaplots.org/PlotlyJS.jl/stable/examples/subplots/) and [here](https://plotly.com/julia/subplots/), and also in some other places. But with no success.

Thanks.

---

<div class="post-metadata">

**Author:** ![halleysfifthinc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/halleysfifthinc/32/206280_2.png) [@halleysfifthinc](https://discourse.julialang.org/u/halleysfifthinc)\
**Post date:** [November 15, 2023, 6:01pm UTC](https://discourse.julialang.org/t/plotlyjs-and-subplots-shared-yaxis-range/106238/2 "2023-11-15T18:01:26Z")

</div>

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.
