我正在使用 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)
当前输出:
最佳答案
您可以 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))))
关于Python Plotly scatter 3D plot colormap自定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70871976/