[Drawing and labeling multiple graphs] Plotly dynamic visualization [python3, make subplot, xlabel, ylabel]

python==3.8 plotly==4.10.0

With plotly settings I'm going to add something I use often

Subplot the drawing

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(rows=1, cols=2)
fig.add_trace(go.Scatter(y=[4, 2, 1], mode="lines"), row=1, col=1)
fig.add_trace(go.Bar(y=[2, 1, 3]), row=1, col=2)
fig.show()

image.png

Background color

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(rows=1, cols=2)
fig.add_trace(go.Scatter(y=[4, 2, 1], mode="lines"), row=1, col=1)
fig.add_trace(go.Bar(y=[2, 1, 3]), row=1, col=2)

fig.update_layout(
    margin=dict(l=20, r=20, t=20, b=20),
    paper_bgcolor="LightSteelBlue",
)

fig.show()

image.png

x, y label title

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(rows=1, cols=2)
fig.add_trace(go.Scatter(y=[4, 2, 1], mode="lines"), row=1, col=1)
fig.add_trace(go.Bar(y=[2, 1, 3]), row=1, col=2)

fig.update_layout(
    margin=dict(l=20, r=20, t=20, b=20),
    paper_bgcolor="LightSteelBlue",
)


fig.update_xaxes(title_text="xlabel")
fig.update_yaxes(title_text="ylabel", hoverformat=".3f")

fig.show()

image.png

Special plot allocation

bar and scattor can be specified as make_subplots, pie and scatter3D cannot be specified as they are Tell make_subplots what you want to specify

Specified by specs

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(
    rows=2, cols=2,
    specs=[[{"type": "bar"}, {"type": "barpolar"}],
           [{"type": "pie"}, {"type": "scatter3d"}]],
)

fig.add_trace(go.Bar(y=[2, 3, 1]),row=1, col=1)
fig.add_trace(go.Barpolar(theta=[0, 45, 90], r=[2, 3, 1]),row=1, col=2)
fig.add_trace(go.Pie(values=[2, 3, 1]),row=2, col=1)
fig.add_trace(go.Scatter3d(x=[2, 3, 1], y=[0, 0, 0], z=[0.5, 1, 2], mode="lines"),row=2, col=2)

fig.update_layout(height=700, showlegend=False)

fig.show()

image.png

that's all

Postscript record

2020-09-27 Created

Recommended Posts

[Drawing and labeling multiple graphs] Plotly dynamic visualization [python3, make subplot, xlabel, ylabel]
[Talking about the drawing structure of plotly] Dynamic visualization with plotly [python]
[Visualization of ratio] Plotly and dynamic visualization [python, pie, sunburst, sanky, treemap, fannele,]
[Density visualization] Plotly and dynamic visualization [python3, hist, kde, join, contour, heat map]
[EDA super basic] Plotly and dynamic visualization [python3, table, bar, box, violin, joy]
[Scatter plot, 3D plot and regression plane] Plotly dynamic visualization [python, scatter, 3D, surface, pair, joint]
[Various image analysis with plotly] Dynamic visualization with plotly [python, image]
[Write to map with plotly] Dynamic visualization with plotly [python]
[Python] Ravel () is convenient when drawing multiple graphs
[# 2] Make Minecraft with Python. ~ Model drawing and player implementation ~
[Time series with plotly] Dynamic visualization with plotly [python, stock price]