Plotly subplots¶
In [1]:
Copied!
import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import arcadia_pycolor as apc
apc.plotly.setup()
x_data = np.random.randint(1, 100, 100)
y_data = np.random.randint(1, 100, 100)
z_data = np.random.randint(1, 100, 100)
colorbar_styles = apc.plotly.get_arcadia_styles()["coloraxis"]["colorbar"]
bar_trace = go.Bar(x=x_data, y=y_data, marker_color=apc.colors.tumbleweed)
heatmap_trace = go.Heatmap(
z=z_data.reshape(10, 10),
colorscale=apc.gradients.magma.to_plotly_colorscale(),
colorbar=dict(**colorbar_styles),
)
scatter_trace_2d = go.Scatter(
x=x_data,
y=y_data,
marker=dict(
color=z_data,
colorscale=apc.gradients.magma.to_plotly_colorscale(),
),
mode="markers",
)
scatter_trace_3d = go.Scatter3d(
x=x_data,
y=y_data,
z=z_data,
mode="markers",
marker=dict(
size=3,
color=z_data,
colorscale=apc.gradients.magma.to_plotly_colorscale(),
),
)
import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import arcadia_pycolor as apc
apc.plotly.setup()
x_data = np.random.randint(1, 100, 100)
y_data = np.random.randint(1, 100, 100)
z_data = np.random.randint(1, 100, 100)
colorbar_styles = apc.plotly.get_arcadia_styles()["coloraxis"]["colorbar"]
bar_trace = go.Bar(x=x_data, y=y_data, marker_color=apc.colors.tumbleweed)
heatmap_trace = go.Heatmap(
z=z_data.reshape(10, 10),
colorscale=apc.gradients.magma.to_plotly_colorscale(),
colorbar=dict(**colorbar_styles),
)
scatter_trace_2d = go.Scatter(
x=x_data,
y=y_data,
marker=dict(
color=z_data,
colorscale=apc.gradients.magma.to_plotly_colorscale(),
),
mode="markers",
)
scatter_trace_3d = go.Scatter3d(
x=x_data,
y=y_data,
z=z_data,
mode="markers",
marker=dict(
size=3,
color=z_data,
colorscale=apc.gradients.magma.to_plotly_colorscale(),
),
)
1. Figure with 2D subplots¶
In [2]:
Copied!
fig = make_subplots(rows=1, cols=2, specs=[[{"type": "xy"}, {"type": "xy"}]])
fig.add_trace(bar_trace, row=1, col=1)
fig.add_trace(heatmap_trace, row=1, col=2)
apc.plotly.style_plot(fig, monospaced_axes="all", row=1, col=1)
apc.plotly.style_plot(fig, monospaced_axes="all", row=1, col=2)
apc.plotly.hide_axis_lines(fig, row=1, col=2)
fig.update_layout(height=350)
fig.show()
fig = make_subplots(rows=1, cols=2, specs=[[{"type": "xy"}, {"type": "xy"}]])
fig.add_trace(bar_trace, row=1, col=1)
fig.add_trace(heatmap_trace, row=1, col=2)
apc.plotly.style_plot(fig, monospaced_axes="all", row=1, col=1)
apc.plotly.style_plot(fig, monospaced_axes="all", row=1, col=2)
apc.plotly.hide_axis_lines(fig, row=1, col=2)
fig.update_layout(height=350)
fig.show()
2. Figure with 3D subplots¶
In [3]:
Copied!
fig = make_subplots(rows=1, cols=2, specs=[[{"type": "scene"}, {"type": "scene"}]])
fig.add_trace(scatter_trace_3d, row=1, col=1)
fig.add_trace(scatter_trace_3d, row=1, col=2)
apc.plotly.style_plot(fig, monospaced_axes="all", row=1, col=1)
apc.plotly.style_plot(fig, monospaced_axes="all", row=1, col=2)
apc.plotly.hide_axis_lines(fig, row=1, col=2)
fig.update_layout(height=350, showlegend=False)
fig.show()
fig = make_subplots(rows=1, cols=2, specs=[[{"type": "scene"}, {"type": "scene"}]])
fig.add_trace(scatter_trace_3d, row=1, col=1)
fig.add_trace(scatter_trace_3d, row=1, col=2)
apc.plotly.style_plot(fig, monospaced_axes="all", row=1, col=1)
apc.plotly.style_plot(fig, monospaced_axes="all", row=1, col=2)
apc.plotly.hide_axis_lines(fig, row=1, col=2)
fig.update_layout(height=350, showlegend=False)
fig.show()
3. Figure with 2D and 3D subplots¶
In [4]:
Copied!
fig = make_subplots(
rows=2,
cols=2,
specs=[[{"type": "xy"}, {"type": "xy"}], [{"type": "xy"}, {"type": "scene"}]],
)
fig.add_trace(bar_trace, row=1, col=1)
fig.add_trace(heatmap_trace, row=1, col=2)
fig.add_trace(scatter_trace_2d, row=2, col=1)
fig.add_trace(scatter_trace_3d, row=2, col=2)
for i in range(1, 3):
for j in range(1, 3):
apc.plotly.style_plot(fig, monospaced_axes="all", row=i, col=j)
apc.plotly.hide_axis_lines(fig, row=1, col=2)
fig.update_layout(height=700, showlegend=False)
fig.show()
fig = make_subplots(
rows=2,
cols=2,
specs=[[{"type": "xy"}, {"type": "xy"}], [{"type": "xy"}, {"type": "scene"}]],
)
fig.add_trace(bar_trace, row=1, col=1)
fig.add_trace(heatmap_trace, row=1, col=2)
fig.add_trace(scatter_trace_2d, row=2, col=1)
fig.add_trace(scatter_trace_3d, row=2, col=2)
for i in range(1, 3):
for j in range(1, 3):
apc.plotly.style_plot(fig, monospaced_axes="all", row=i, col=j)
apc.plotly.hide_axis_lines(fig, row=1, col=2)
fig.update_layout(height=700, showlegend=False)
fig.show()