# Surface3D with customdata

Hello,

I working with plotly in python in order to create a sphere.
First, I have phi, theta and power which are 3 arrays of n values.

``````    phi, theta, power
[  0.,   0.,  30.],
[ 15.,   0.,  30.],
[ 30.,   0.,  30.],
...,
[345.,   0.,  30.],
[360.,   0.,  30.],
[  0.,  15.,  30.],
[ 15.,  15.,  30.],
[ 30.,  15.,  30.],
...
[360.,  15.,  30.],
....
[345., 180.,  30.],
[360., 180.,  30.]])
``````

Then, I have to create x, y and z which are 13x25 matrix. When I run the code, I have perfectly what I want concerning the visualisation of the sphere. But, the custom data doesnβt work, for example, some points donβt have value.

fig = go.Figure(data=[go.Surface(x=x, y=y, z=z,

``````                                surfacecolor=R3d,

colorscale='Rainbow',

customdata=customdata,

hovertemplate='<b>%{customdata}</b>'

)])
``````

Can you help me ?

Help @pierredamien welcome to the Plotly family
Are you referring to the hover that is missing some values?

Yes, I am refering to the hover values. Because the plot only show x,y and z which is by default. But I would like also to see with hover the value for phi theta and power.
So this is what I would like for my customdata.

@pierredamien,
Iβm not qute sure I understood the definition of your theta, phi and power. Here is an example when they are defined as arrays of the same shape like x, y, z:

``````import numpy as np
from numpy import pi, cos, sin
import plotly.graph_objects as go

theta = np.linspace(0, 2*pi, 72)
phi = np.linspace(-pi/2, pi/2, 36)
theta, phi = np.meshgrid(theta, phi)
x = cos(theta) * cos(phi)
y = sin(theta) * cos(phi)
z = sin(phi)

power = np.random.randint(2, 10, theta.shape)
customdata = np.stack((theta, phi, power), axis=-1)

hover = 'theta: %{customdata[0]:.3f}'+\
'<br>phi: %{customdata[1]: .3f}'+\
'<br>power: %{customdata[2]:.3f}<extra></extra>'

fig = go.Figure(go.Surface(x=x, y=y, z=z,
customdata=customdata,
hovertemplate = hover))
``````

In fact I wanted to plot an antenna radio pattern so I have theta and phi which change to measure the power received. Then with these measurements I have to plot the radio pattern.
You answer seems to be interesting but if you hover the plot some points are missing too.

@pierredamien

I donβt know why the hover text is displayied like that for you.
Here is my plot (Plotly 4.9.0):

Do you get all the points from the entire sphere ? Even behind the sphere of the default camera ?

@pierredamien

You are right!! I think there is a bug in displaying hovertemplate for 3d, because if I rotate the sphere, the hovertext looks like in your posted image above.
Iβve just opened this issue https://github.com/plotly/plotly.js/issues/5003 on plotly.js.

1 Like

Ok great thank you ! Fortunately, I can use scatter3d for the moment which is working. So, I will wait for the hovertemplate of surface3d !
Thank you again for your help.

Is it a problem if you opened the issue on plotly.js instead of plotly.py ?

@pierredamien This is a plotly.js issue not a plotly.py. Plotly.py is built on top of plotly.js. The latter is responsible for displaying the charts.

1 Like