# Displaying Z values in 3D Surface Plot

**URL:** <https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410>\
**Category:** plotly.js\
**Tags:** question\
**Created:** [March 9, 2023, 3:30pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410 "2023-03-09T15:30:02Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonim](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anonim](https://community.plotly.com/u/anonim)\
**Post date:** [March 9, 2023, 3:30pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/1 "2023-03-09T15:30:02Z")

</div>

Hello, i’m using Plotly javascript library, i have a 3D surface plot, which i convert it to 2D looking (like in this example: [Projection of 3d surface in Python/v3](https://plotly.com/python/v3/2d-projection-of-3d-surface/)) grid (image is below), what i want is that somehow i want to display Z values in each boxes in the grid, couldn’t find any way to do it, is it even possible to do that?

Note: Z values are set to 0 in order to make the plot look like 2D grid, i can have another array that has some values and i still want to display/print them on the grid.

You can check the codes and everything: [https://codepen.io/anonim11/pen/KKxyQNY](https://codepen.io/anonim11/pen/KKxyQNY)

 ![Screenshot 2023-03-09 at 6.25.14 PM](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/9/0/909030f549c6a32890e7d98f1f4d61160ed41a7e.png)

to

 ![Screenshot 2023-03-09 at 6.25.14 PM](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/0/0/00fa59a3ff8ab6e7df131456aefde1111c6df0b3.png)

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [March 11, 2023, 3:09pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/2 "2023-03-11T15:09:59Z")

</div>

Hi @anonim welcome to the forums. Is there a reason for using 3D surface plots and then reducing it to 2D? Couldn’t you use an annotated heatmap?

> **[Heatmaps](https://plotly.com/javascript/heatmaps/#annotated-heatmap)**
>
> Over 12 examples of Heatmaps including changing color, size, log axes, and more in JavaScript.

---

<div class="post-metadata">

**Author:** ![anonim](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anonim](https://community.plotly.com/u/anonim)\
**Post date:** [March 18, 2023, 10:23pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/3 "2023-03-18T22:23:44Z")

</div>

Hello @AIMPED, sorry for late reply, i honestly thought nobody was going to say something. I’ve tried heatmaps but couldn’t get exactly what i wanted to do. The reason i’m using 3D surface plots is that, i have a 3D surface plot with depths etc. and i wanted to show exactly as is how it looks in 2D surface.

For example, in the picture below i’m using surfacecolor to point out the depth but in 2D. You can kinda understand how it would look in 3D surface plot. If i would be able to get same view with heatmaps, i think i would use it, but i want my 2D looking exactly like the 3D surface plot, but again, with 2D version.

Pretty much like in this example: [https://chart-studio.plotly.com/create/?fid=jordanpeterson:1174#/](https://chart-studio.plotly.com/create/?fid=jordanpeterson:1174#/) but with grid lines and the Z values on it.

 ![Screenshot 2023-03-19 at 1.18.14 AM](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/6/d/6d60b79edf32f709311519889e6de00e7a81f29c.png)

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [March 18, 2023, 10:26pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/4 "2023-03-18T22:26:30Z")

</div>

No problem. I’m pretty sure this is possible to do. Are you able to share sample data?

---

<div class="post-metadata">

**Author:** ![anonim](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anonim](https://community.plotly.com/u/anonim)\
**Post date:** [March 18, 2023, 10:35pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/5 "2023-03-18T22:35:05Z")

</div>

@AIMPED

X: [[30,30,30,30,30],[60,60,60,60,60],[90,90,90,90,90],[120,120,120,120,120],[150,150,150,150,150]]  
Y: [[30,60,90,120,150],[30,60,90,120,150],[30,60,90,120,150],[30,60,90,120,150],[30,60,90,120,150]]  
Z: [[3283,1667,978,3781,2942],[1757,3798,4517,1448,3838],[3513,2001,4473,3891,2041],[1143,660,1431,2886,4372],[914,933,3891,4829,1053]]

What i got with these data right now:

 ![Screenshot 2023-03-19 at 1.32.48 AM](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/7/5/75221429b766a2a7b12984199a584e02bc0aba03.png)

I would like something like that, also notice that i expect 5 boxes in X axis and 5 boxes in Y axis, but some boxes are missing in my case, maybe because of i’m using 3D surface plot. Also it would be great if i’m able to customize text style/size/alignment and everything on the grid.

 ![Screenshot 2023-03-19 at 1.36.17 AM](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/e/9/e910e8f23b3da765b281a6539dfde203417675d2.png)

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [March 18, 2023, 11:22pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/6 "2023-03-18T23:22:57Z")

</div>

Why do you expect 5 “boxes”?

Z.shape = (5,5), in order to have 5 “boxes” you would need 6 data points. The 5 data points are the values on the grid line crossings.

I played around with `go.Contour`, could you share your code for this figure?

> **[Contour](https://plotly.com/python/contour-plots/)**
>
> Over 14 examples of Contour Plots including changing color, size, log axes, and more in Python.

```python
import plotly.graph_objects as go
import numpy as np

X= np.asarray([[30,30,30,30,30],[60,60,60,60,60],[90,90,90,90,90],[120,120,120,120,120],[150,150,150,150,150]])
Y= np.asarray([[30,60,90,120,150],[30,60,90,120,150],[30,60,90,120,150],[30,60,90,120,150],[30,60,90,120,150]])
Z= np.asarray([[3283,1667,978,3781,2942],[1757,3798,4517,1448,3838],[3513,2001,4473,3891,2041],[1143,660,1431,2886,4372],[914,933,3891,4829,1053]])

contour = go.Figure(
    layout={'width': 400, 'height':400 },
    data=go.Contour(
        z=Z,
        line_smoothing=0,
        contours_coloring='heatmap'
    ) 
)
contour.update_yaxes(
    scaleanchor="x",
    scaleratio=1,
  )
contour.show()

```

![newplot(55)](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/7/d/7d95ccd7272ff5778748d899d04dea85182728ae.png)

---

<div class="post-metadata">

**Author:** ![anonim](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anonim](https://community.plotly.com/u/anonim)\
**Post date:** [March 18, 2023, 11:33pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/7 "2023-03-18T23:33:43Z")

</div>

Yes i need 6 data points but since i have 5 value in each array in Z, i wanted to show all values on the grid. I may add a fake non-visible data point for that, not sure yet.

You can check my code with the data i’ve shared before. You’ll see it’s a bit weird how i’ve done this, it’s because i just wasn’t be able to find a way to do it exactly how i wanted to do, so i’ve tried to go around for everything i wanted to do 😕

https://codepen.io/anonim11/embed/preview/KKxyQNY?default-tabs=js%2Cresult&height=300&host=https%3A%2F%2Fcodepen.io&slug-hash=KKxyQNY

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [March 18, 2023, 11:45pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/8 "2023-03-18T23:45:44Z")

</div>

I just noticed the plotly JS tag on this topic 🙈

I think the easiest way to show the data points would be to add a scatter trace, setting the marker color to rgba(0,0,0,0) and showing the text only, pretty much like here:

> [@Custom marker characters](https://community.plotly.com/t/custom-marker-characters/73527/2):
>
> Hi @abhinavk welcome to the forums. You could use the text argument: import plotly.graph\_objects as go import numpy as np fig = go.Figure() for fac, txt in enumerate('ABCDE'): fig.add\_scatter( x=np.arange(1, 10), y=np.arange(1, 10) + 10\*fac, mode='text+lines', text=txt, name=f'trace\_{txt}') fig.show() creates: [newplot (10)]

Sorry, I can’t really help with JS 😉

---

<div class="post-metadata">

**Author:** ![anonim](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anonim](https://community.plotly.com/u/anonim)\
**Post date:** [March 18, 2023, 11:51pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/9 "2023-03-18T23:51:04Z")

</div>

@AIMPED Oh okay, thanks anyway, but i assume python or javascript doesn’t change plots etc. so i would be still interested and see if you would be able to do what i’m trying to do in python 🙂

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [March 18, 2023, 11:59pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/10 "2023-03-18T23:59:15Z")

</div>

> [@anonim](#):
>
> python or javascript doesn’t change plots

True.

Just to clarify: You want to see the 3d plot, on the bottom the 2D heatmap/contour with grid lines and values as text for each data point.

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [March 20, 2023, 3:02pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/11 "2023-03-20T15:02:44Z")

</div>

Maybe this (python) thread helps?

> [@How to plot a 2d Graph on the background (side wall) of a 3d Plot](https://community.plotly.com/t/how-to-plot-a-2d-graph-on-the-background-side-wall-of-a-3d-plot/72874):
>
> Hi, I have a sample 3d plot (shown in the following) and as you see the side walls (Backgrounds) are colored. import plotly.graph\_objects as go import numpy as np t = np.linspace(-1, 1.2, 500) x = (t\*\*3) + (0.3 \* np.random.randn(500)) y = (t\*\*6) + (0.3 \* np.random.randn(500)) z=(t\*\*2) + (0.3 \* np.random.randn(500)) fig = go.Figure() fig.add\_scatter3d( x = x, y = y, z = z, mode = 'markers', marker = dict( color = 'rgba(0,0,0,0.3)', size = 3) ) fig.update\_layout( auto…

---

<div class="post-metadata">

**Author:** ![anonim](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anonim](https://community.plotly.com/u/anonim)\
**Post date:** [March 22, 2023, 5:22pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/12 "2023-03-22T17:22:35Z")

</div>

@AIMPED At least for me, didn’t help and i still couldn’t do it.

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [March 22, 2023, 5:34pm UTC](https://community.plotly.com/t/displaying-z-values-in-3d-surface-plot/73410/13 "2023-03-22T17:34:04Z")

</div>

OK, I’ll give it a try when I find the time 🙈
