Colouring a surface using Mesh3d in python plotly

I would aim to colour a surface in a 3D plot, created using plotly.graph_objects.

I worked on an approach incorporating Mesh3d, the code runs, but the wanted surface is still not coloured. What is the mistake I made, or should another approach be used?

The final outcome is desired to look similar to this 3D plot:

And this is where I am at now (I don’t aim to apply color scaling to the surface, it is good enough to be filled with a consistent colour):

So, the aim would be to colour the surface where the vertical lines are connecting the two curves (2D and the same in 3D).

Here is my code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import plotly.graph_objects as go
import numpy as np
def plot_3d_course_profile(x, y, z, color_attribute, colorbar_label):
fig = go.Figure()
# Bottom curve at altitude = 350
fig.add_trace(go.Scatter3d(
x=x,
y=y,
z=[350] * len(x),
mode='lines',
line=dict(
color='black',
width=5,
)
))
# Profile curve
fig.add_trace(go.Scatter3d(
x=x,
y=y,
z=z,
mode='lines',
line=dict(
color=color_attribute,
width=13,
colorscale='Jet',
colorbar=dict(
title=dict(
text=colorbar_label,
font=dict(size=14, color='black')
),
thickness=20,
len=0.6,
tickfont=dict(size=12, color='black'),
tickmode='linear',
tickformat='.2f',
outlinewidth=1,
outlinecolor='black'
)
)
))
# Vertical lines
for i in range(0, len(x), 7):
xi, yi, zi = x[i], y[i], z[i]
fig.add_trace(go.Scatter3d(
x=[xi, xi],
y=[yi, yi],
z=[350, zi],
mode='lines',
line=dict(color='dimgray', width=4),
opacity=0.6,
showlegend=False
))
# surface - not displaying
fig.add_trace(go.Mesh3d(
x=np.concatenate([x, x[::-1]]),
y=np.concatenate([y, y[::-1]]),
z=np.concatenate([[350] * len(x), z[::-1]]),
color='blue',
opacity=0.5,
showscale=False
))
fig.update_layout(
template='plotly_white',
scene=dict(
xaxis=dict(title='Meters north from start position', showgrid=True, gridcolor='lightblue', zeroline=False),
yaxis=dict(title='Meters east from start position', showgrid=True, gridcolor='lightblue', zeroline=False),
zaxis=dict(title='Altitude [m]', showgrid=True, gridcolor='lightblue', zeroline=False),
aspectmode='manual',
aspectratio=dict(x=1.25, y=1, z=0.7)
),
title=f'3D Course Profile Colored by {colorbar_label}',
margin=dict(l=0, r=0, b=0, t=50)
)
fig.show()
</code>
<code>import plotly.graph_objects as go import numpy as np def plot_3d_course_profile(x, y, z, color_attribute, colorbar_label): fig = go.Figure() # Bottom curve at altitude = 350 fig.add_trace(go.Scatter3d( x=x, y=y, z=[350] * len(x), mode='lines', line=dict( color='black', width=5, ) )) # Profile curve fig.add_trace(go.Scatter3d( x=x, y=y, z=z, mode='lines', line=dict( color=color_attribute, width=13, colorscale='Jet', colorbar=dict( title=dict( text=colorbar_label, font=dict(size=14, color='black') ), thickness=20, len=0.6, tickfont=dict(size=12, color='black'), tickmode='linear', tickformat='.2f', outlinewidth=1, outlinecolor='black' ) ) )) # Vertical lines for i in range(0, len(x), 7): xi, yi, zi = x[i], y[i], z[i] fig.add_trace(go.Scatter3d( x=[xi, xi], y=[yi, yi], z=[350, zi], mode='lines', line=dict(color='dimgray', width=4), opacity=0.6, showlegend=False )) # surface - not displaying fig.add_trace(go.Mesh3d( x=np.concatenate([x, x[::-1]]), y=np.concatenate([y, y[::-1]]), z=np.concatenate([[350] * len(x), z[::-1]]), color='blue', opacity=0.5, showscale=False )) fig.update_layout( template='plotly_white', scene=dict( xaxis=dict(title='Meters north from start position', showgrid=True, gridcolor='lightblue', zeroline=False), yaxis=dict(title='Meters east from start position', showgrid=True, gridcolor='lightblue', zeroline=False), zaxis=dict(title='Altitude [m]', showgrid=True, gridcolor='lightblue', zeroline=False), aspectmode='manual', aspectratio=dict(x=1.25, y=1, z=0.7) ), title=f'3D Course Profile Colored by {colorbar_label}', margin=dict(l=0, r=0, b=0, t=50) ) fig.show() </code>
import plotly.graph_objects as go
import numpy as np

def plot_3d_course_profile(x, y, z, color_attribute, colorbar_label):
    fig = go.Figure()

    # Bottom curve at altitude = 350
    fig.add_trace(go.Scatter3d(
        x=x,
        y=y,
        z=[350] * len(x),
        mode='lines',
        line=dict(
            color='black',
            width=5,
        )
    ))

    # Profile curve
    fig.add_trace(go.Scatter3d(
        x=x,
        y=y,
        z=z,
        mode='lines',
        line=dict(
            color=color_attribute,
            width=13,
            colorscale='Jet',
            colorbar=dict(
                title=dict(
                    text=colorbar_label,
                    font=dict(size=14, color='black')
                ),
                thickness=20,
                len=0.6,
                tickfont=dict(size=12, color='black'),
                tickmode='linear',
                tickformat='.2f',
                outlinewidth=1,
                outlinecolor='black'
            )
        )
    ))

    # Vertical lines
    for i in range(0, len(x), 7):
        xi, yi, zi = x[i], y[i], z[i]
        fig.add_trace(go.Scatter3d(
            x=[xi, xi],
            y=[yi, yi],
            z=[350, zi],
            mode='lines',
            line=dict(color='dimgray', width=4),
            opacity=0.6,
            showlegend=False
        ))

        # surface - not displaying
    fig.add_trace(go.Mesh3d(
        x=np.concatenate([x, x[::-1]]),  
        y=np.concatenate([y, y[::-1]]),
        z=np.concatenate([[350] * len(x), z[::-1]]),
        color='blue',
        opacity=0.5,
        showscale=False
    ))
        
    fig.update_layout(
        template='plotly_white',
        scene=dict(
            xaxis=dict(title='Meters north from start position', showgrid=True, gridcolor='lightblue', zeroline=False),
            yaxis=dict(title='Meters east from start position', showgrid=True, gridcolor='lightblue', zeroline=False),
            zaxis=dict(title='Altitude [m]', showgrid=True, gridcolor='lightblue', zeroline=False),
            aspectmode='manual',
            aspectratio=dict(x=1.25, y=1, z=0.7)
        ),
        title=f'3D Course Profile Colored by {colorbar_label}',
        margin=dict(l=0, r=0, b=0, t=50)
    )

    fig.show() 

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật