简体   繁体   中英

Python Plotly scatter 3D plot colormap customization

I am using plotly. I am getting the plot. The problem is, I am using seasons as colormap. I have used 1 for fall, 2 for winter, ..,4 for summer. Now, the colomap shows these numbers and also 1.5, 2.5 etc. I want to show Names instead of numbers

My code:

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)

Present output:

在此处输入图像描述

You can modify the coloraxis by adding the following lines to your code:

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

Sample output with random data: 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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