import plotly as plt
import plotly.express as px
iris = plt.data.iris()
iris.head()
px.box(
iris,
x="petal_width",
y="petal_length",
color="species",
points="all")
Is it possible to distinguish the species of each point by color, but have unified boxes for each x value? For example at x=1.5, there are two boxes for versicolor and virginica. I want just one box, but with color-coded individual points.
1 Like
import plotly as plt
import plotly.express as px
iris = plt.data.iris()
iris.head()
test_fig = px.box(
iris,
x="petal_width",
y="petal_length",
points=False)
for _species in iris["species"].unique():
_data = iris.loc[iris["species"]==_species, :]
test_fig = test_fig.add_scatter(
x=_data["petal_width"] - 0.035,
y=_data["petal_length"],
mode="markers",
name=_species
)
test_fig
Of course this manual adding of traces is possible, but I hope thereβs also more straightforward solution.