Search code examples
pythonplotly-python

Plotly 3D Surface Cutting Out Data


I tried this code with Plotly 5.10.0:

import plotly.graph_objects as go
import numpy as np


x = np.arange(0, 10)
y = np.arange(0.5, 1.525, 0.025)

np.random.seed(56)
z = np.random.uniform(0.1, 0.5, size=(len(x), len(y)))

fig = go.Figure(go.Surface(
    x=x,
    y=y,
    z=z)
)
fig.show()

The y values in the data should range up to 1.5, but in the resulting plot the y axis values cut off at 0.725:

plot with y axis cut off

Why does this occur? I can't find anything in the docs or provided examples that explains the result.


Solution

  • This is the same problem as this. If you use the transpose of Z it should work.

    import plotly.graph_objects as go
    import numpy as np
    
    x = np.arange(0, 10)
    y = np.arange(0.5, 1.525, 0.025)
    
    np.random.seed(56)
    z = np.random.uniform(0.1, 0.5, size=(len(x), len(y)))
    
    fig = go.Figure(go.Surface(
        x=x,
        y=y,
        z=z.T)
    )
    
    fig.show()
    

    On your original script, x has 10 elements so only the first 10 elements of y were being used by go.Surface.