# How plot relational graphs

**URL:** <https://community.plotly.com/t/how-plot-relational-graphs/62810>\
**Category:** Dash Python\
**Created:** [April 7, 2022, 12:48pm UTC](https://community.plotly.com/t/how-plot-relational-graphs/62810 "2022-04-07T12:48:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ettan](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@ettan](https://community.plotly.com/u/ettan)\
**Post date:** [April 7, 2022, 12:48pm UTC](https://community.plotly.com/t/how-plot-relational-graphs/62810/1 "2022-04-07T12:48:53Z")

</div>

Hi,

Does anyone know whether it is possible to plot a relational graph in plotly? Something like [sns.relplot in seaborn](https://seaborn.pydata.org/generated/seaborn.relplot.html) that looks like this:

 ![Screenshot 2022-04-07 at 13.48.23](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/c/b/cbf81c759ebd3cb556fb5d05b547a6e2bba942d4.jpeg)

Thanks.

---

<div class="post-metadata">

**Author:** ![stu](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/stu/32/18439_2.png) [@stu](https://community.plotly.com/u/stu)\
**Post date:** [April 7, 2022, 1:18pm UTC](https://community.plotly.com/t/how-plot-relational-graphs/62810/2 "2022-04-07T13:18:20Z")

</div>

> [@ettan](#):
>
> relational

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

> **[Subplots](https://plotly.com/python/subplots/)**
>
> Over 17 examples of Subplots including changing color, size, log axes, and more in Python.

---

<div class="post-metadata">

**Author:** ![ettan](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@ettan](https://community.plotly.com/u/ettan)\
**Post date:** [April 7, 2022, 1:41pm UTC](https://community.plotly.com/t/how-plot-relational-graphs/62810/3 "2022-04-07T13:41:12Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![stu](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/stu/32/18439_2.png) [@stu](https://community.plotly.com/u/stu)\
**Post date:** [April 7, 2022, 1:46pm UTC](https://community.plotly.com/t/how-plot-relational-graphs/62810/4 "2022-04-07T13:46:29Z")

</div>

```auto
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")
fig.show()

```

> **[Subplots](https://plotly.com/python/subplots/)**
>
> Over 17 examples of Subplots including changing color, size, log axes, and more.

---

<div class="post-metadata">

**Author:** ![adamschroeder](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adamschroeder/32/17280_2.png) [@adamschroeder](https://community.plotly.com/u/adamschroeder)\
**Post date:** [April 8, 2022, 1:04pm UTC](https://community.plotly.com/t/how-plot-relational-graphs/62810/5 "2022-04-08T13:04:58Z")

</div>

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)](https://plotly.com/python/splom/) or [facet plots](https://plotly.com/python/facet-plots/).

---

<div class="post-metadata">

**Author:** ![nicolaskruchten](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/nicolaskruchten/32/7018_2.png) [@nicolaskruchten](https://community.plotly.com/u/nicolaskruchten)\
**Post date:** [April 9, 2022, 9:11pm UTC](https://community.plotly.com/t/how-plot-relational-graphs/62810/6 "2022-04-09T21:11:20Z")

</div>

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.
