更改 Plotly 散点图颜色

Change Plotly scatter plot color

我正在尝试通过 plotly 可视化 4-class 数据集。

对于以下代码: fig = px.scatter_3d(df_pca, x='pca1', y='pca2', z='pca3', color = 'emotion')

我得到下图,不方便理解,因为“蓝色”和“紫色”颜色“难以辨认”。

所以我想将“紫色”颜色更改为“黄色”。你能建议如何巧妙地做到这一点吗?该文档似乎没有太大帮助。

我在文档中找到了这个color_discrete_sequence参数,也许它可以帮助你https://plotly.com/python/discrete-color/#explicitly-constructing-a-color-sequence

import plotly.express as px
df = px.data.gapminder().query("year == 2007")
fig = px.bar(df, y="continent", x="pop", color="continent", orientation="h", hover_name="country",
             color_discrete_sequence=["red", "green", "blue", "goldenrod", "magenta"],
             title="Explicit color sequence"
            )

fig.show()