# Make\_subplots(): Two rows, One column

**URL:** <https://discourse.julialang.org/t/make-subplots-two-rows-one-column/86179>\
**Category:** General Usage\
**Tags:** plotlyjs\
**Created:** [August 23, 2022, 9:26am UTC](https://discourse.julialang.org/t/make-subplots-two-rows-one-column/86179 "2022-08-23T09:26:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [August 23, 2022, 9:26am UTC](https://discourse.julialang.org/t/make-subplots-two-rows-one-column/86179/1 "2022-08-23T09:26:31Z")

</div>

Yesterday it gave me an headache, why I can not plot two figures on top of each other,  
the problem is related to the topic:  
[how-to-create-a-2x1-array](https://discourse.julialang.org/t/how-to-create-a-2x1-array/8337/40).

Here is my example:

```julia
using PlotlyJS

hdl_trace1 = scatter(x=[1, 2], y=[1, 2], name="(1,1)")
hdl_trace2 = scatter(x=[1, 2], y=[2, 3], name="(1,2)")

hdl_plt = make_subplots(rows=2, cols=1, specs = reshape([Spec(kind="xy") Spec(kind="xy")], :, 1) )
hdl_plt = make_subplots(rows=2, cols=1, specs = permutedims([Spec(kind="xy") Spec(kind="xy")]))

println(string("window_size = ", size(hdl_plt) ) )

add_trace!(hdl_plt, hdl_trace1, row=1, col=1)
add_trace!(hdl_plt, hdl_trace2, row=2, col=1)

relayout!(hdl_plt, title_text="Example subplots: two row by one colum plot")
display(hdl_plt)

```

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [August 23, 2022, 9:58am UTC](https://discourse.julialang.org/t/make-subplots-two-rows-one-column/86179/2 "2022-08-23T09:58:21Z")

</div>

Is this a question or an example of a solution?

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [August 23, 2022, 10:44am UTC](https://discourse.julialang.org/t/make-subplots-two-rows-one-column/86179/3 "2022-08-23T10:44:19Z")

</div>

Hi, thanks for your feedback!  
The related question could be: What is wrong here?

```julia
using PlotlyJS
hdl_plt = make_subplots(rows=2, cols=1, specs = [Spec(kind="xy") Spec(kind="xy")])

```

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [August 23, 2022, 11:08am UTC](https://discourse.julialang.org/t/make-subplots-two-rows-one-column/86179/4 "2022-08-23T11:08:51Z")

</div>

I agree, it is somewhat unintuitive as the linked post makes clear. One might expect this to work:

```julia
hdl_plt = make_subplots(rows=2, cols=1, specs = [Spec(kind="xy") ; Spec(kind="xy")])

```

Notice I’ve added a semicolon between, to create a `2-element Vector{Spec}` to correspond tor 2 rows with 1 column. But still `spec` needs to be a `Matrix` type, while a `Vector` type causes an error! It is surprising.

You can also use `missing` “to move past a col/row span” as is says under `spec` in the help of `make_subplots`:

```julia
hdl_plt = make_subplots(rows=2, cols=1, specs = [Spec(kind="xy") missing; Spec(kind="xy") missing])

```

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [August 23, 2022, 12:37pm UTC](https://discourse.julialang.org/t/make-subplots-two-rows-one-column/86179/5 "2022-08-23T12:37:48Z")

</div>

In fact I also began yesterday to play around with the placeholder “missing”, but I tried this trick only inside a large script, not suitable to be shared.  
The strange thing is, a “poor mens solution” that works inside this large script, fails inside a minamal example.  
Therefore, the next two questions:

- does the example work on your machine?
- if it fails, what is wrong? why does this work in a large script but not in an example?

```julia
using PlotlyJS
hdl_trace1 = PlotlyJS.scatter(x=[1, 2], y=[1, 2], name="(raw#1, col#1)")
hdl_trace2 = PlotlyJS.scatter(x=[1, 2], y=[2, 3], name="(raw#2, col#1)")
hdl_plt = [hdl_trace1; hdl_trace2]
PlotlyJS.relayout!(hdl_plt, title_text = "Example subplots: Simple version two row by one colum plot")
hdl_plt = PlotlyJS.display(hdl_plt)

```

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [August 24, 2022, 1:14am UTC](https://discourse.julialang.org/t/make-subplots-two-rows-one-column/86179/6 "2022-08-24T01:14:42Z")

</div>

This example doesn’t work with a `MethodError` for `relayout!`. Here is how I would do this:

```julia
using PlotlyJS
hdl_plot1 = PlotlyJS.Plot(PlotlyJS.scatter(x=[1, 2], y=[1, 2], name="(row#1, col#1)"))
hdl_plot2 = PlotlyJS.Plot(PlotlyJS.scatter(x=[1, 2], y=[2, 3], name="(row#2, col#1)"))
hdl_plt = [hdl_plot1; hdl_plot2]

PlotlyJS.relayout!(hdl_plt, title_text = "Example subplots: Simple version two row by one column plot")
hdl_plt = PlotlyJS.display(hdl_plt)

```

Here I’ve wrapped the traces in the `Plot()` function before using the concatenation syntax `[hdl_plot1; hdl_plot2]`.
