Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch direction of axis in 3D scatterplot plotly?

I plotted the following using plotly and got the resulting plot shown before. X is the # of hours in a day, Y is a proportion between 0-1, and Z is a categorical variable with levels {0,1,2}.

However, it's unclear why the X seems to be going the opposite direction of what we're used to with a 3D Cartesian place where it's down(-) and up(+), left(-) and right(+), and front(-) and back(+). However, X seems to decrease from front to back instead of increase. I am new to plotly and am not sure how to flip the axis so it goes from 0 to 1 instead of 1 to 0. I would greatly appreciate help on this!

fig = px.scatter_3d(X_combined, x='x', y='y', z='z',
          color='set', symbol='predictions', opacity=0.7)

fig.update_traces(marker=dict(size=12,
                         line=dict(width=5,
                         color='Black')),
                  selector=dict(mode='markers'))

Plotly plot

like image 640
Jane Sully Avatar asked Nov 25 '25 03:11

Jane Sully


1 Answers

For 3D plots, the options for axes are under layout.scene.
The autorange option is therefore located under layout.scene.xaxis.autorange and can be modified like this:

fig.update_scenes(xaxis_autorange="reversed")

References:

  • python/3d-axes
  • python/layout-scene-xaxis-autorange
like image 155
Tanel Peet Avatar answered Nov 27 '25 17:11

Tanel Peet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!