Hello together,
I finally found an issue with plotly that I couldn’t resolve. I would like to plot the example in
3d surface plots in Python (plotly.com)
in several sublots. My goal is a plot in the following form:
But I just can’t to get it to work in the form of the following subplots:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=2, cols=2)
fig.add_trace(
go.Scatter(x=[1, 2, 3], y=[4, 5, 6]),
row=1, col=1
)
fig.add_trace(
go.Scatter(x=[20, 30, 40], y=[50, 60, 70]),
row=1, col=2
)
fig.add_trace(
go.Scatter(x=[20, 30, 40], y=[50, 60, 70]),
row=2, col=1
)
fig.add_trace(
go.Scatter(x=[20, 30, 40], y=[50, 60, 70]),
row=2, col=2
)
fig.update_layout(height=600, width=800, title_text="Side By Side Subplots")
fig.show()
The example with the 3 surfaces is the following:
import plotly.graph_objects as go
import numpy as np
z1 = np.array([
[8.83,8.89,8.81,8.87,8.9,8.87],
[8.89,8.94,8.85,8.94,8.96,8.92],
[8.84,8.9,8.82,8.92,8.93,8.91],
[8.79,8.85,8.79,8.9,8.94,8.92],
[8.79,8.88,8.81,8.9,8.95,8.92],
[8.8,8.82,8.78,8.91,8.94,8.92],
[8.75,8.78,8.77,8.91,8.95,8.92],
[8.8,8.8,8.77,8.91,8.95,8.94],
[8.74,8.81,8.76,8.93,8.98,8.99],
[8.89,8.99,8.92,9.1,9.13,9.11],
[8.97,8.97,8.91,9.09,9.11,9.11],
[9.04,9.08,9.05,9.25,9.28,9.27],
[9,9.01,9,9.2,9.23,9.2],
[8.99,8.99,8.98,9.18,9.2,9.19],
[8.93,8.97,8.97,9.18,9.2,9.18]
])
z2 = z1 + 1
z3 = z1 - 1
fig = go.Figure(data=[
go.Surface(z=z1),
go.Surface(z=z2, showscale=False, opacity=0.9),
go.Surface(z=z3, showscale=False, opacity=0.9)
])
fig.show()
But how can I get 4 sublots of it?
I somehow can’t manage to integrate the “data” array to the fig.add_trace above.
Any help is highly appreciated!
Thanks in advance
James