pythonplotlysurface

Plotting a surface over lines plotly


I have this code snipped, that should plot a surface over a few lines:

import plotly.graph_objects as go
import plotly.io as pio
import math
import numpy as np

t_changes = np.linspace((0.005*2*math.pi)/60 , (1*2*math.pi)/60 , 10)

omega_all = np.linspace((1*2*math.pi)/60  ,(12*2*math.pi)/60 , 10)

max_values_all = [1.4185558393536863, 1.4325906947905434, 1.438658017942095, 1.4806644284478363, 1.4761508670671415, 1.4649492471829895, 1.464546919691028, 1.4578007061068432, 1.4428714932707587, 1.4500144702965356],[1.6441629388568684, 1.642323391267553, 1.6491736867101752, 1.6412988007431675, 1.6290382708032518, 1.687033971399921, 1.7249970205847203, 1.7375113332368095, 1.734492370556642, 1.7242648069286037],[2.0845437496335575, 2.072843683096361, 2.035169117911497, 2.063686038710132, 1.966491883139673, 2.036435788844538, 2.000384950132592, 1.9602627462709168, 1.9992717869448466, 2.02862099663119],[3.3253818185735087, 3.1215539630481604, 2.981889203258018, 2.8546336239840215, 2.7042612422101002, 2.575780911605224, 2.5755048740741917, 2.6205430458363095, 2.576086019821094, 2.487398700065042],[15.432838261722877, 6.5095720712941985, 5.200282346853118, 4.495357558732455, 4.136530871191216, 3.766634997051916, 3.6827888643956186, 3.4764385554542914, 3.430120257752737, 3.4201713261825426],[75.66433489618231, 15.94566966995464, 10.161220922127605, 8.007523032946853, 6.800634588849489, 6.000935050965966, 5.536898133810305, 5.21365607068837, 5.010566351336815, 4.708208983726101],[75.66286832418304, 15.363231967657855, 15.81080564424909, 13.0105751921456, 11.001714824633169, 9.553264617238883, 8.572992551192133, 8.004222045653602, 7.365317024063387, 7.085229662879642],[75.66242236630372, 15.363226081588929, 10.955988755682252, 13.158249063867139, 14.179122828320526, 13.460821531609223, 12.624633192306533, 11.937231489633758, 11.274180241228226, 10.672516546418693],[75.65799160190585, 21.62711751806979, 18.008379194730093, 14.53079025616018, 8.520673195597784, 14.016979085011064, 16.276408102947748, 17.05937073631494, 17.220381393056392, 16.8222819511244],[118.96662233164312, 66.31352570490306, 68.16962905085047, 61.396954421293266, 74.95559072827379, 67.92902322683065, 63.00643530404031, 63.21829273940191, 65.26976962802642, 67.46680681352494]
fig = go.Figure()

# Loop through each line and add it to the figure
for i in range(len(omega_all)):
    x_vals = [omega_all[i]*60/(2*math.pi)]* len(t_changes)
    y_vals = t_changes
    z_vals = max_values_all[i]
    fig.add_trace(go.Scatter3d(x=x_vals, y=y_vals, z=z_vals, mode='lines'))


fig.add_trace(go.Surface(x=(omega_all*60/(2*math.pi)), y=t_changes, z=max_values_all))
# Set layout
fig.update_layout(scene=dict(aspectmode="cube"))

# Show the figure
fig.show()

But the result is this:

enter image description here

I don't get why, maybe you can help.

As you can see the lines are plotted just fine but the surface is on the wrong side and not very accuratly tracing the lines in my opinion.


Solution

  • Please check this one?

    We just need to create the list & put the value in it

    import plotly.graph_objects as go
    import plotly.io as pio
    import math
    import numpy as np
    
    t_changes = np.linspace((0.005*2*math.pi)/60 , (1*2*math.pi)/60 , 10)
    
    omega_all = np.linspace((1*2*math.pi)/60  ,(12*2*math.pi)/60 , 10)
    
    max_values_all = [1.4185558393536863, 1.4325906947905434, 1.438658017942095, 1.4806644284478363, 1.4761508670671415, 1.4649492471829895, 1.464546919691028, 1.4578007061068432, 1.4428714932707587, 1.4500144702965356],[1.6441629388568684, 1.642323391267553, 1.6491736867101752, 1.6412988007431675, 1.6290382708032518, 1.687033971399921, 1.7249970205847203, 1.7375113332368095, 1.734492370556642, 1.7242648069286037],[2.0845437496335575, 2.072843683096361, 2.035169117911497, 2.063686038710132, 1.966491883139673, 2.036435788844538, 2.000384950132592, 1.9602627462709168, 1.9992717869448466, 2.02862099663119],[3.3253818185735087, 3.1215539630481604, 2.981889203258018, 2.8546336239840215, 2.7042612422101002, 2.575780911605224, 2.5755048740741917, 2.6205430458363095, 2.576086019821094, 2.487398700065042],[15.432838261722877, 6.5095720712941985, 5.200282346853118, 4.495357558732455, 4.136530871191216, 3.766634997051916, 3.6827888643956186, 3.4764385554542914, 3.430120257752737, 3.4201713261825426],[75.66433489618231, 15.94566966995464, 10.161220922127605, 8.007523032946853, 6.800634588849489, 6.000935050965966, 5.536898133810305, 5.21365607068837, 5.010566351336815, 4.708208983726101],[75.66286832418304, 15.363231967657855, 15.81080564424909, 13.0105751921456, 11.001714824633169, 9.553264617238883, 8.572992551192133, 8.004222045653602, 7.365317024063387, 7.085229662879642],[75.66242236630372, 15.363226081588929, 10.955988755682252, 13.158249063867139, 14.179122828320526, 13.460821531609223, 12.624633192306533, 11.937231489633758, 11.274180241228226, 10.672516546418693],[75.65799160190585, 21.62711751806979, 18.008379194730093, 14.53079025616018, 8.520673195597784, 14.016979085011064, 16.276408102947748, 17.05937073631494, 17.220381393056392, 16.8222819511244],[118.96662233164312, 66.31352570490306, 68.16962905085047, 61.396954421293266, 74.95559072827379, 67.92902322683065, 63.00643530404031, 63.21829273940191, 65.26976962802642, 67.46680681352494]
    fig = go.Figure()
    
    lx = []
    ly = []
    lz = []
    # Loop through each line and add it to the figure
    for i in range(len(omega_all)):
        x_vals = [omega_all[i]*60/(2*math.pi)]* len(t_changes)
        y_vals = t_changes
        z_vals = max_values_all[i]
        lx.append(x_vals)
        ly.append(y_vals)
        lz.append(z_vals)
        fig.add_trace(go.Scatter3d(x=x_vals, y=y_vals, z=z_vals, mode='lines'))
    
    
    fig.add_trace(go.Surface(x=lx, y=ly, z=lz))
    # Set layout
    fig.update_layout(scene=dict(aspectmode="cube"))
    
    # Show the figure
    fig.show()
    

    Here is the result

    enter image description here

    Also, the problem is came from the max_values_all is a tuple of lists, not a list like the t_changes & omega_all