PlotlyJS subplots

Is there a way how to plot subplots containing more than one scatter plot?

Here is just example where I tried to put 3 scatter plots into the first subplot:

using  PlotlyBase

trace1a = scatter(x=1:3, y=2:4)
trace1b = scatter(x=1:3, y=3:7)
trace1c = scatter(x=1:3, y=10:20)
trace1 = [trace1a , trace1b, trace1c ]
trace2 = scatter(x=20:10:40, y=[5,5,5], xaxis="x2", yaxis="y")
trace3 = scatter(x=2:4, y=200:100:800, xaxis="x", yaxis="y3")
trace4 = scatter(x=4000:1000:6000, y=7000:1000:9000, xaxis="x4", yaxis="y4")
data = [trace1, trace2, trace3, trace4]
layout = Layout(
    grid=attr(
        rows=2, columns=2, subplots=[["xy", "x2y"], ["xy3", "x4y4"]],
        roworder="bottom to top"
    )
)
Plot(data, layout)

Have you tried this?
http://juliaplots.org/PlotlyJS.jl/stable/examples/subplots/

2 Likes

Thank you, I somehow missed it.

Thanks @PetrKryslUCSD

Hi @Oto_Brzobohaty, you can use the built in plotly.js subplot tools

I think the problem was that you need to splat the trace1 when creating the data array (by doing trace1...). As writetn in the original post, data will be a 4 element array, where the first element is itself an array of traces. What we want here is an array of 6 traces.

Here’s a working example (note that I also removed the roworder="bottom to top" in the layout because that was causing the bottom row to be filled in first, so xy was bottom left instead of top left):

using PlotlyBase

trace1a = scatter(x=1:3, y=2:4)
trace1b = scatter(x=1:3, y=3:7)
trace1c = scatter(x=1:3, y=10:20)
trace1 = [trace1a , trace1b, trace1c ]
trace2 = scatter(x=20:10:40, y=[5,5,5], xaxis="x2", yaxis="y")
trace3 = scatter(x=2:4, y=200:100:800, xaxis="x", yaxis="y3")
trace4 = scatter(x=4000:1000:6000, y=7000:1000:9000, xaxis="x4", yaxis="y4")
data = [trace1..., trace2, trace3, trace4]

layout = Layout(
    grid=attr(
        rows=2, columns=2, subplots=[["xy", "x2y"], ["xy3", "x4y4"]],
#         roworder="bottom to top"
    )
)

Plot(data, layout)
1 Like

Sorry for reviving this old thread. I rewrote the code in the post above like this

trace1a = scatter(x=1:3, y=2:4, xaxis="x", yaxis="y")
trace1b = scatter(x=1:3, y=3:7, xaxis="x", yaxis="y")
trace1c = scatter(x=1:3, y=10:20, xaxis="x", yaxis="y")
trace2 = scatter(x=20:10:40, y=[5,5,5], xaxis="x2", yaxis="y")
trace3 = scatter(x=2:4, y=200:100:800, xaxis="x", yaxis="y3")
trace4 = scatter(x=4:6, y=7000:1000:9000, xaxis="x4", yaxis="y4")

plot([trace1a, trace1b, trace1c, trace2, trace3, trace4],
     Layout(grid=attr(rows=2, columns=2,
                      subplots=[["xy", "x2y"], ["xy3", "x4y4"]])))

However, if I change the definition for trace4 and the grid attribute in the following way

trace4 = scatter(x=4:6, y=7000:1000:9000, xaxis="x", yaxis="y4") #xaxis="x" instead of "x4"

plot([trace1a, trace1b, trace1c, trace2, trace3, trace4],
     Layout(grid=attr(rows=2, columns=2,
                      subplots=[["xy", "x2y"], ["xy3", "xy4"]]))) # "xy4" instead of "x4y4"

the plot is messed up: