Skip to content

Plotly Subplots and Facets

Two ways to create multi-plot layouts

  1. Facets (Plotly Express): easiest for grid layouts
  2. Subplots (plotly.subplots): full control

Facets with Plotly Express

Facet example
import plotly.express as px
 
df = px.data.tips()
 
fig = px.scatter(
    df,
    x="total_bill",
    y="tip",
    color="sex",
    facet_col="day",
    title="Tips by day (facets)",
)
fig.show()
Facet example
import plotly.express as px
 
df = px.data.tips()
 
fig = px.scatter(
    df,
    x="total_bill",
    y="tip",
    color="sex",
    facet_col="day",
    title="Tips by day (facets)",
)
fig.show()

Manual subplots

Subplots
import plotly.graph_objects as go
from plotly.subplots import make_subplots
 
fig = make_subplots(rows=1, cols=2, subplot_titles=["A", "B"])
 
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 4, 9], mode="lines", name="line"), row=1, col=1)
fig.add_trace(go.Bar(x=["x", "y", "z"], y=[5, 2, 6], name="bar"), row=1, col=2)
 
fig.update_layout(title_text="Two plots in one figure")
fig.show()
Subplots
import plotly.graph_objects as go
from plotly.subplots import make_subplots
 
fig = make_subplots(rows=1, cols=2, subplot_titles=["A", "B"])
 
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 4, 9], mode="lines", name="line"), row=1, col=1)
fig.add_trace(go.Bar(x=["x", "y", "z"], y=[5, 2, 6], name="bar"), row=1, col=2)
 
fig.update_layout(title_text="Two plots in one figure")
fig.show()

Tips

  • Use facets when you’re comparing the same chart across categories.
  • Use subplots when mixing chart types.

If this helped you, consider buying me a coffee β˜•

Buy me a coffee

Was this page helpful?

Let us know how we did