I am having trouble creating subplots in plotly given a pandas data frame with multiple colors.
Here is an incomplete example creating the individual plots:
import plotly
df = plotly.express.data.iris()
plot1 = plotly.express.scatter(df, x="sepal_width", y="sepal_length", color="species")
plot2 = plotly.express.scatter(df, x="petal_width", y="petal_length", color="species")
plot1.show(), plot2.show()
From what I read, something like this makes sense but does not work:
import plotly
df = plotly.express.data.iris()
plot1 = plotly.express.scatter(df, x="sepal_width", y="sepal_length", color="species")
plot2 = plotly.express.scatter(df, x="petal_width", y="petal_length", color="species")
fig = plotly.subplots.make_subplots(rows=1, cols=2)
fig.append_trace(plot1, row=1, col=1)
fig.append_trace(plot2, row=1, col=2)
fig.show()
Looking into this, others seem to resolve this issue with a similar setup:
https://stackoverflow.com/a/65555470/4700548
r-beginners gives a good example below of how to make multiple subplots with one color, but this causes performance issues with many colors.
What is it that I am missing in these examples?
Edit: Added color to example. Added incomplete example.