Ankur Kumar
Ankur Kumar

Reputation: 51

Change X,Y and Z axis at (0,0,0) in Scatter 3D plot using Plotlyexpress

I wish to plot a 3D scatter plot using plotly.express and wish to fix the X,Y and Z axis at (0,0,0) rather than the minimum value. I tried with matplotlib and changed the ylim and xlim but there is no such options in Plotly.express.

Can someone please help me achieve the above?

I am attaching a sample dataset and other required details. Sample Dataset with 3 numerical columns This is a scatter plot but the axis is at minimum

I need to replace the -200 at each axes with 0.

Code:

import plotly.express as plt plt.scatter(x="X",y="Y",data_frame=data)

Upvotes: 0

Views: 1779

Answers (1)

r-beginners
r-beginners

Reputation: 35230

Restricting 3D axes is accomplished by specifying a range of x, y, and z axes for the scene in Layout Change. See the official reference.

import plotly.express as px

fig = px.scatter_3d(df, x='X', y='Y', z='Z')

fig.update_layout(autosize=False,
                  height=600,
                  width=600,
                  scene=dict(
                      xaxis = dict(nticks=6, range=[0,300],),
                      yaxis = dict(nticks=6, range=[0,500],),
                      zaxis = dict(nticks=6, range=[0,500],)
                  )
                 )
fig.show()

enter image description here

Upvotes: 1

Related Questions