gpt4 book ai didi

Python Plotly scatter 3D plot colormap自定义

转载 作者:行者123 更新时间:2023-12-05 05:48:06 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com