Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Plotly scatter 3D plot colormap customization

Tags:

python

plotly

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:

enter image description here

like image 857
Mainland Avatar asked Jun 27 '26 07:06

Mainland


1 Answers

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: enter image description here

like image 84
Mr. T Avatar answered Jun 29 '26 20:06

Mr. T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!