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?
Asked
Active
Viewed 2,346 times
2 Answers
4
You can use px.scatter_matrix
.
Plotly scatter_matrix Documentation
EDIT: Sorry, missed the on the x-axis part.
The easiest way to do this is to use the facet_col
parameter.
import plotly.express as px
from plotly.subplots import make_subplots
df = px.data.iris()
fig = px.scatter(df,
x = 'sepal_length',
y = 'petal_length',
color = 'species',
facet_col= 'species',
template = 'plotly_dark'
)
fig.show()

joshyewa
- 72
- 4
1
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()

Hamzah
- 8,175
- 3
- 19
- 43