pythonplotlyscatter3d

Truncated figure with plotly


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:

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


Solution

  • 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