How plot relational graphs


Does anyone know whether it is possible to plot a relational graph in plotly? Something like sns.relplot in seaborn that looks like this:


What do you mean by ‘relational’? If you’re looking for subplots, see this.

@stu Relational meaning all the plots share the same x and y axis.

Seaborn allows you to plot all the graphs in 1 function. If i use subplots on plotly, it looks like i’ll have to individually add 15 subplots to the figure? Is there another way to do it?

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

fig = make_subplots(rows=2, cols=2, shared_yaxes=True)

fig.add_trace(go.Scatter(x=[1, 2, 3], y=[2, 3, 4]),
              row=1, col=1)

fig.add_trace(go.Scatter(x=[20, 30, 40], y=[5, 5, 5]),
              row=1, col=2)

fig.add_trace(go.Scatter(x=[2, 3, 4], y=[600, 700, 800]),
              row=2, col=1)

fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]),
              row=2, col=2)

fig.update_layout(height=600, width=600,
                  title_text="Multiple Subplots with Shared Y-Axes")

Hi @ettan
@stu 's answer is probably the best way since it gives you a lot more control. But you can also use splom (scatter matrix) or facet plots.

This looks like a job for something like px.line(df, x="period_reference", y="goods_value_gbp_millions", color="period_year", facet_col="sector", facet_col_wrap=3) plus some tweaks for color.