# PlutoPlotly and PlotlyJS: subplots

**URL:** https://discourse.julialang.org/t/plutoplotly-and-plotlyjs-subplots/87886
**Category:** General Usage
**Tags:** plotting, subplots
**Created:** [September 27, 2022, 7:01pm UTC](https://discourse.julialang.org/t/plutoplotly-and-plotlyjs-subplots/87886 "2022-09-27T19:01:59Z")
**Posts on this page:** 3
**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: [September 27, 2022, 7:01pm UTC](https://discourse.julialang.org/t/plutoplotly-and-plotlyjs-subplots/87886/1 "2022-09-27T19:01:59Z")

</div>

Hi,  
I am trying to produce a figure with two subplots in Pluto, using PlotlyJS and PlutoPlotly. If I create each plot individually, there is no problem: all the layout attributes of the individual plots will come out correctly. However, when I produce a figure with the two subplots, some attributes come out OK (like titles, hover, names), but not `shapes`. Strangely, shapes are supposed to appear in both subplots, but they are only visible in the first subplot. Unfortunately, I do need the shapes to appear in all subplots.

As usual, @empet solved my problem [here](https://discourse.julialang.org/t/plotlyjs-subplots-and-individual-layouts/87740):

```julia
using PlotlyJS
fig= make_subplots(rows=1, cols=2, subplot_titles=["Some noise" "More noise"])
add_trace!(fig, scatter(;x=1:50, y=rand(50), name = "some"), row=1, col=1)
add_trace!(fig, scatter(;x=1:50, y=rand(50), name = "more"), row=1, col=2)
relayout!(fig, hovermode="x")
add_vrect!(fig, 5, 10, fillcolor = "red", opacity = 0.2, line_width = 0; row=1, col=1)
add_vrect!(fig, 20, 26, fillcolor = "blue", opacity = 0.2, line_width = 0; row=1, col=2)
display(fig)

```

If I run @empet’s code in Atom/VScode, having the internal plot pane activated, the figure with subplots comes out OK, and no error is thrown out.

 ![ab](https://global.discourse-cdn.com/julialang/original/3X/d/b/db3cb5a5e30f701d5d6826b821ec7bf2655963aa.png)

However, suppose the external plot window is activated. In that case, the figure is still produced, but an infinite set of garbage pops out – as soon as we click on the figure – alleging problems with WebSockets, Mux, Blink, and WebIO.

The same code also works very well in VSCode/Atom `using PlotlyJS, ElectronDisplay` as proposed by @stephancb[here](https://discourse.julialang.org/t/state-of-plotlyjs-and-support-packages/86119/6)

Nevertheless, I need these figures in Pluto, not Atom or VScode. I tried to replicate the same code in Pluto (v0.19.12), using PlotlyJS (v018.8) and PlutoPlotly (v.03.4). Still faced two problems: (i) without `using WebIO`, no plot is produced, and the infamous error `WebIO not detected` pops up.; (ii) with `using WebIO`, no error is thrown out, but the figure is nowhere to be seen. In the latter case, if I close the block by using `display(fig)`, this is what I get:

 ![bb](https://global.discourse-cdn.com/julialang/original/3X/8/2/82c1741350fcd16ad7c9ec52b950f69f426106ad.png)

and if I opt for closing the block by calling `fig` , nothing comes out.

I get the same behavior by using PlutoPlotly.jl or @disberd’s initial workaround to integrate PlotlyJS inside Pluto [here](https://discourse.julialang.org/t/pluto-plots-with-plotlybase-plotlyjs-with-working-static-html-export/61730).

Help will be very much appreciated. Thanks

---

<div class="post-metadata">

### Author: ![disberd](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@disberd](https://discourse.julialang.org/u/disberd)
#### Post date: [September 28, 2022, 8:13am UTC](https://discourse.julialang.org/t/plutoplotly-and-plotlyjs-subplots/87886/2 "2022-09-28T08:13:17Z")

</div>

Hi @VivMendes the problem here is that the function `make_subplots` is defined inside `PlotlyJS` and not inside `PlotlyBase` and it automatically create a `SyncPlot` (also from `PlotlyJS`) rather than a normal `Plot` object.

the function is quite simple, so for the time being you can just plug in this code to make it work:

```julia
begin
	fig= Plot(Layout(Subplots(rows=1, cols=2, subplot_titles=["Some noise" "More noise"])))
	add_trace!(fig, scatter(;x=1:50, y=rand(50), name = "some"), row=1, col=1)
	add_trace!(fig, scatter(;x=1:50, y=rand(50), name = "more"), row=1, col=2)
	relayout!(fig, hovermode="x")
	add_vrect!(fig, 5, 10, fillcolor = "red", opacity = 0.2, line_width = 0; row=1, col=1)
	add_vrect!(fig, 20, 26, fillcolor = "blue", opacity = 0.2, line_width = 0; row=1, col=2)
	PlutoPlotly.plot(fig) # This need to be the `plot` function from PlutoPlotly, not from PlotlyJS
end

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/b/1b954f89971574463701203204f4e29c78ce238a.png)

Now that I am back from holidays I have to work on some backlog stuff on PlutoPlotly to fix some things and make it more compliant with standard PlotlyJS usage, so hopefully within the next week or so you could still use the same code you use in PlotlyJS outside of Pluto without modifications.  
Remember though that PlutoPlotly and PlotlyJS are not supposed to be imported together (at least not both with `using`) in a single notebook.  
I will also try to adapt PlutoPlotly to be compliant with the recent [JuliaPlots/PlotlyKaleido.jl (github.com)](https://github.com/JuliaPlots/PlotlyKaleido.jl) so that you don’t have to load PlotlyJS to use `savefig` anymore.

---

<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: [September 28, 2022, 2:06pm UTC](https://discourse.julialang.org/t/plutoplotly-and-plotlyjs-subplots/87886/3 "2022-09-28T14:06:56Z")

</div>

Hi @disberd, thank you so much. Your solution works nicely. It is a pleasure to work with Pluto and PlotlyJS, and you made it possible and efficient with your PlutoPlotly package. It works much faster than producing the plots in VSCode or Atom.
