Plotly: How to manually set the color of points in plotly express scatter plots?

As far as I understand your question, I would try to answer it.

The parameter 'color' only accepts the column names.
In your case, you can consider using update_traces()

import as px
df = # iris is a pandas DataFrame
fig = px.scatter(df, x="sepal_width", y="sepal_length")


For that you may use the color_discrete_sequence argument.

fig = px.scatter(df, x="sepal_width", y="sepal_length", color_discrete_sequence=['red'])

This argument is to use a custom color paletter for discrete color factors, but if you are not using any factor for color it will use the first element for all the points in the plot.

More about discrete color palletes:

You do not have to add another feature to get what you want here. Thanks to Python's method chaining, you can just include .update_traces(marker=dict(color='red')) to manually assign any color of your choosing to all markers.


enter image description here


# x and y given as DataFrame columns
import as px
df = # iris is a pandas DataFrame
fig = px.scatter(df,x="sepal_width",