Is it possible to do a "pair plot" in plolty?

Viewed 23

In plotly for python, is there anyway to do a plot with multiple variables on the x-axis against a single variable on the y-axis? The scatter_matrix function uses every variable combination, but I am looking for just a single variable on the y-axis. In seaborn, the graph below is easy to produce with pairplot, but can it be done in plotly?

enter image description here

1 Answers

Yes, you can use subplot with row = 1 and columns = whatever you want, like that:

import plotly.express as px
from plotly.subplots import make_subplots

df = px.data.iris()

fig = make_subplots(rows=1, cols=3)

fig.add_trace(
    go.Scatter(x=df["sepal_width"], y=df["petal_length"], mode="markers",name="Scatter 1"),
    row=1, col=1
)

fig.add_trace(
    go.Scatter(x=df["sepal_length"], y=df["petal_length"], mode="markers",name="Scatter 2"),
    row=1, col=2
)

fig.add_trace(
    go.Scatter(x=df["petal_width"], y=df["petal_length"], mode="markers", name="Scatter 3",),
    row=1, col=3
)


fig.show()

enter image description here

Related