Python Plotly scatter 3D plot colormap自定义

标签 python plotly

我正在使用 plotly。我明白了。问题是,我使用季节作为颜色图。我秋天用了 1 个,冬天用了 2 个,夏天用了 ..,4 个。现在,Colomap 显示这些数字以及 1.5、2.5 等。我想显示名称而不是数字

我的代码:

import plotly.express as px
from plotly.offline import plot
import plotly
fig = px.scatter_3d(df, x=xlbl, y=ylbl, z=zlbl,
              color=wlbl,opacity=0,
              color_continuous_scale  = plotly.colors.sequential.Viridis)
temp_name = 'Temp_plot.html'
plot(fig, filename = temp_name, auto_open=False,
     image_width=1200,image_height=800)    
plot(fig)

当前输出:

enter image description here

最佳答案

您可以 modify the coloraxis通过将以下行添加到您的代码中:

cat_labels = ["Fall", "Winter", "Spring", "Summer"]
fig.update_coloraxes(colorbar=dict(ticktext=cat_labels, 
                                   tickvals=list(range(1, len(cat_labels)+1))))

带有随机数据的示例输出: enter image description here

关于Python Plotly scatter 3D plot colormap自定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70871976/

相关文章:

python - 如何保存输入的文本? (Python)

r - 生成 R 绘图列表并将其传递给子图

python - 使用 plotly.express 折线图,线条以奇怪的顺序连接?怎么修?

r - 散点图中的颜色编码误差条

python - Swig 包装一个 C++ 数据类型?

python - 什么是 python 'in' 但对于 sqlalchemy

R Plot_ly : How to change colorbar color palette and colorthreshold values?

r - 如何在 R Shiny 中显示来自 plotly_click 的许多点?

python - python if 中的复合 bool 逻辑

Python:直接从 Pandas 加载 Oracle 表(写入 Oracle)