[Python] Create a 3D surface plot in Plotly

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    I want to create a 3D surface plot in Plotly by reading the data from an external file. Following is the code I am using:

    import numpy as np
    import plotly.graph_objects as go
    import plotly.express as px


    data = np.genfromtxt('values.dat', dtype=float)

    # The shape of X, Y and Z is (10,1)
    X = data[:,0:1]
    Y = data[:,1:2]
    Z = data[:,2:3]

    fig = go.Surface(x=X, y=Y, z=Z, name='Surface plot', colorscale=px.colors.sequential.Plotly3)
    plot(fig)


    The above code does not produce any surface plot. What changes has to be made to create a surface plot?

    Continue reading...

Compartilhe esta Página