# Assign color bar to x axis

**URL:** <https://community.plotly.com/t/assign-color-bar-to-x-axis/38594>\
**Category:** 📊 Plotly Python\
**Created:** [April 28, 2020, 11:48pm UTC](https://community.plotly.com/t/assign-color-bar-to-x-axis/38594 "2020-04-28T23:48:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DennisPureza](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@DennisPureza](https://community.plotly.com/u/DennisPureza)\
**Post date:** [April 28, 2020, 11:48pm UTC](https://community.plotly.com/t/assign-color-bar-to-x-axis/38594/1 "2020-04-28T23:48:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Emmanuelle](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emmanuelle/32/7853_2.png) [@Emmanuelle](https://community.plotly.com/u/Emmanuelle)\
**Post date:** [April 29, 2020, 8:49am UTC](https://community.plotly.com/t/assign-color-bar-to-x-axis/38594/2 "2020-04-29T08:49:13Z")

</div>

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

```auto
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))
fig.show()

```

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/2/271c8e235078547334ea15c5fecfc37c86b4221e.png)

---

<div class="post-metadata">

**Author:** ![DennisPureza](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@DennisPureza](https://community.plotly.com/u/DennisPureza)\
**Post date:** [April 30, 2020, 2:49am UTC](https://community.plotly.com/t/assign-color-bar-to-x-axis/38594/3 "2020-04-30T02:49:24Z")

</div>

Thank you! It worked perfectly!
