2

I am facing a problem with the Scatter3d from plotly: the figure is always truncated at the bottom:

Truncated scatter 3D

I create the plot via plotly.express this way:

fig = px.scatter_3d(BFM_pcaFull, x=0, y=1, z=2, color=3)

with BFM_pcaFull being the pandas.DataFrame where the data are stored. I tried to create the plot via plotly.graph_object instead of plotly.epxress but the result is the same. I tried to tweak the layout parameter via the update_layout() method of fig:

  • Padding
  • Auto margin
  • Scaling
  • scaleratio
  • constrain

of course without any change to the graph (which does surprise me and make me think I am doing something wrong, even if apparently the 3D surface seems to follow different rules somewhat).

An issue for the same problem is open on the Github repo of the project but has not been solved so far (https://github.com/plotly/plotly.py/issues/3785).

Has anybody faced the same problem and found a solution by any chance?

Thanks for your help

AlexK
  • 2,855
  • 9
  • 16
  • 27
TSS22
  • 68
  • 6
  • 1
    This is always a troubling event. It can be corrected by modifying the camera angle. See [here for details](https://plotly.com/python/3d-camera-controls/#changing-the-camera-position-by-setting-the-eye-parameter). Whether the result is satisfactory is another matter. Looking at the improved result, I thought that the 3D view was prioritized at the expense of cutting. `fig.update_layout(margin=dict(l=0,r=0,t=0,b=0), scene_camera=dict(eye=dict(x=2.0, y=2.0, z=0.75)))` – r-beginners Aug 01 '22 at 01:38
  • Perfect it absolutely solved the problem (thanks for the edit too). I guess you can put your comment as answer so I can up vote it. Thanks a lot – TSS22 Aug 01 '22 at 06:17

1 Answers1

1

To avoid missing parts of the graph in a 3D graph, you can change the viewpoint angle. See here for more information. The following code can be used to deal with this problem.

import plotly.express as px
df = px.data.iris()
fig = px.scatter_3d(df, x='sepal_length',
                    y='sepal_width', z='petal_width',
                    color='species')
fig.show()

enter image description here

When the camera viewpoint is changed

fig.update_layout(margin=dict(l=0,r=0,t=0,b=0), scene_camera=dict(eye=dict(x=2.0, y=2.0, z=0.75)))

enter image description here

r-beginners
  • 31,170
  • 3
  • 14
  • 32