Python Plotly scatter 3D plot colormap自定义

Python Plotly scatter 3D plot colormap customization

我正在使用plotly。我明白了。问题是,我使用季节作为颜色图。我秋天用了 1 个,冬天用了 2 个,夏天用了 ..,4 个。现在,彩色地图显示了这些数字以及 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)

当前输出:

您可以 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))))

带有随机数据的示例输出: