繁体   English   中英

如何在 Python 中更改 plotly.express 的颜色和大小?

[英]How to change color and size of plotly.express in Python?

我正在使用plotly.express在 Python 中绘制我的人工神经网络图。 我将展示我的代码:

import plotly.express as px
fig = px.scatter(newDf, x="Glucose", y="Age", color="Outcome")
fig.show()

我希望“颜色”(包含结果)的侧边栏只有 0 和 1 值(而不是 0、0.2、0.4...)。 另外,我想更改散点图中点的颜色。 目前,该图具有蓝色 (0) 和黄色 (1) 点,尤其是黄色点,很难看到。

假设你的结果只有0和1的值,最简单的方式,使plotly把它作为一个离散值将其转换为字符串。

df["Outcome"] = df["Outcome"].astype(str) #convert to string

# you can convert back to numeric later, if needed
df["Outcome"] = df["Outcome"].astype(float) 

现在,要更改颜色,您可以像这样使用参数color_discrete_sequence

mport plotly.express as px
fig = px.scatter(newDf, x="Glucose", y="Age", color="Outcome", 
                 color_discrete_sequence= ["blue", "red"])
fig.show()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM