✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Assign color bar to x axis

Hello, in a surface plot, is there a way to define the color of the surface (continuous) and the color bar in relation to the x axis data instead of the default z axis?

Hi @DennisPureza welcome to the forum! Yes this is possible, using the surfacecolor attribute of go.Surface. For example

import plotly.graph_objects as go
import numpy as np
x, y = 4 * np.pi * np.mgrid[0:1:20j, 0:1:20j]
z = np.sin(x)
fig = go.Figure(go.Surface(x=x, y=y, z=z, surfacecolor=x))

Thank you! It worked perfectly!