# Origin Centered Axes

For some reason I have decided to try and remove the backdrop for the Plotly surface and scatter plots and instead place axes lines centered at the origin and place tick numbers along those axes. I have figured out how to remove the backdrop, and make axes, but I am unsure how to place numbers at points in the scene. Any insight would be much appreciated.

edit: added MRE. My goal is to place numbers at specific spots along the lines to effectively make a set of coordinate axes that intersect at the origin.

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

def spherical_coordinates_mesh(res1, res2, res3, phi0=0, theta0=0, r0=0, phi1=0, theta1=0, r1=0):
res1 = complex(res1)
res2 = complex(res2)
res3 = complex(res3)
if phi0 == phi1:
t, r = np.mgrid[theta0:theta1:res2, r0:r1:res3]
x = r*np.cos(phi0)*np.sin(t)
y = r*np.sin(phi0)*np.sin(t)
z = r*np.cos(t)

elif theta0 == theta1:
p, r = np.mgrid[phi0:phi1:res1, r0:r1:res3]
x = r*np.cos(p)*np.sin(theta0)
y = r*np.sin(p)*np.sin(theta0)
z = r*np.cos(theta0)

elif r0 == r1:
p, t = np.mgrid[phi0:phi1:res1, theta0:theta1:res2]
x = r0*np.cos(p)*np.sin(t)
y = r0*np.sin(p)*np.sin(t)
z = r0*np.cos(t)

if phi0 != phi1 and r0 != r1 and theta0 != theta1:
x = 0
y = 0
z = 0

return x, y, z

if __name__ == "__main__":

x, y, z, = spherical_coordinates_mesh(50, 50, 50, phi1 = 2*np.pi, theta1=np.pi, r0=1, r1=1)
fig = go.Figure(data=[go.Surface(x=x, y=y, z=z, colorscale='viridis')])
fig.update_scenes(xaxis_visible=False, yaxis_visible=False,zaxis_visible=False )

e1x, e1y, e1z = np.array([-2.5, 2.5]), np.array([0,0]), np.array([0,0])
axes = go.Scatter3d(x=e1x, y=e1y, z=e1z, mode='lines', showlegend = False)

e2x, e2y, e2z = np.array([0,0]), np.array([-2.5,2.5]), np.array([0,0])
axes = go.Scatter3d(x=e2x, y=e2y, z=e2z, mode='lines', showlegend = False)

e3x, e3y, e3z = np.array([0,0]), np.array([0,0]), np.array([-2.5,2.5])
axes = go.Scatter3d(x=e3x, y=e3y, z=e3z, mode='lines', showlegend = False)
fig.show()
``````

Hi @redhorn welcome to the forums.

Could you add some more infromation? I think a MRE would be the best, if possible.

I edited the original post to add an MRE.

1 Like

Hi @redhorn,

I think the easiest way to do this would be adding some points on your scatter3D which represent your axes.

Using `mode='markers+lines+text'` you should be able to control where to show text and/or marker. An example:

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

fig = go.Figure()
x=[1,2,3],
y=[1,2,3],
z=[1,2,3],
mode='lines+markers+text',
text=['', 'B', 'C'],
marker={
'color': ['red', 'rgba(0,0,0,0)', 'blue']
},
)
``````

creates:

Note that there is no text at the first marker because it has been specified like this in the `text` argument. Same applies for the `marker` argument, the marker color at position ‘B’ is set to be “invisible” through the alpha channel of the rgba string.

That’s pretty much exactly what I was looking for. I didn’t realize I could specify markers, lines and text. Thank You!

1 Like