plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Bug Report: go.Surface doesn't show the outthrust value!

Open lhg1992 opened this issue 7 months ago • 6 comments

I'm coming to report another bug on the go.Surface. As the code shown below, you can easily get the bug. The plotly go.Surface only plots the Contour_Val in rectangular shape. It completely ignores those outthrust values in the 'Contour_Val' matrix.

The Matplotlib shows the correct surface(or contour).

import numpy as np
X=np.array([
       [7800.,   7900.,   8000., 8100., 8200., 8300., 8400., 8500.],
       [7800.,   7900.,   8000., 8100., 8200., 8300., 8400., 8500.],
       [7800.,   7900.,   8000., 8100., 8200., 8300., 8400., 8500.],
       [7800.,   7900.,   8000., 8100., 8200., 8300., 8400., 8500.],
       [7800.,   7900.,   8000., 8100., 8200., 8300., 8400., 8500.],
       [7800.,   7900.,   8000., 8100., 8200., 8300., 8400., 8500.],
       [7800.,   7900., 8000.00, 8100.00, 8200., 8300., 8400., 8500.],
       [7800., 7900.00, 8000.00, 8100., 8200., 8300., 8400., 8500.],
       [7800.,   7900., 8000.00, 8100., 8200., 8300., 8400., 8500.],
       [7800.,   7900.,   8000., 8100., 8200., 8300., 8400., 8500.],
       [7800.,   7900.,   8000., 8100., 8200., 8300., 8400., 8500.]])

Y=np.array([
       [3800.,   3800.,   3800., 3800., 3800., 3800., 3800., 3800.],
       [3900.,   3900.,   3900., 3900., 3900., 3900., 3900., 3900.],
       [4000.,   4000.,   4000., 4000., 4000., 4000., 4000., 4000.],
       [4100.,   4100.,   4100., 4100., 4100., 4100., 4100., 4100.],
       [4200.,   4200.,   4200., 4200., 4200., 4200., 4200., 4200.],
       [4300.,   4300.,   4300., 4300., 4300., 4300., 4300., 4300.],
       [4400.,   4400., 4400.00, 4400.00, 4400., 4400., 4400., 4400.],
       [4500., 4500.00, 4500.00, 4500., 4500., 4500., 4500., 4500.],
       [4600.,   4600., 4600.00, 4600., 4600., 4600., 4600., 4600.],
       [4700.,   4700.,   4700., 4700., 4700., 4700., 4700., 4700.],
       [4800.,   4800.,   4800., 4800., 4800., 4800., 4800., 4800.]])

Contour_Val= np.array([
       [          np.nan,         np.nan,         np.nan,         np.nan,         np.nan,         np.nan,         np.nan,         np.nan],
       [          np.nan,         np.nan,         np.nan, 12169.04428749,         np.nan,         np.nan,         np.nan,         np.nan],
       [          np.nan,         np.nan,         np.nan, 12128.33946596, 12114.37604446,         np.nan,         np.nan,         np.nan],
       [          np.nan,         np.nan, 12146.50058674, 12110.75061221, 12094.0645444 ,         np.nan,         np.nan,         np.nan],
       [          np.nan,         np.nan, 12154.96379352, 12116.42568321,         np.nan,         np.nan,         np.nan,         np.nan],
       [          np.nan,         np.nan, 12186.79247811, 12145.38853514,         np.nan,         np.nan,         np.nan,         np.nan],
       [          np.nan,         np.nan, 12241.85245564, 12197.51679624,         np.nan,         np.nan,         np.nan,         np.nan],
       [          np.nan, 12385.14869121, 12319.78169639,         np.nan,         np.nan,         np.nan,         np.nan,         np.nan],
       [          np.nan,         np.nan, 12419.96884955,         np.nan,         np.nan,         np.nan,         np.nan,         np.nan],
       [          np.nan,         np.nan,         np.nan,         np.nan,         np.nan,         np.nan,         np.nan,         np.nan],
       [          np.nan,         np.nan,         np.nan,         np.nan,         np.nan,         np.nan,         np.nan,         np.nan]])


# %% matplotlib version
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection='3d')
ax.set_proj_type('ortho') 
ax.axis('equal')
surf = ax.contourf(X, Y, Contour_Val, zdir='z', 
                offset=50,  # plot at z=offset
                cmap='jet')
ax.set_xlim([X.min(), X.max()])
ax.set_ylim([Y.min(), Y.max()])
ax.set_zlim([0, 100])

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.view_init(elev=90, azim=0)

# show the figure
plt.show()
# %% plotly version
'''
bug: the outthrust values are not plotted!
'''
import plotly.graph_objects as go

plotz=50
Z=np.full_like(Contour_Val, plotz)
mask = np.isnan(Contour_Val) # mask for NaN values
Z[mask]=np.nan  # apply mask to Z

fig = go.Figure()
fig.add_trace( go.Surface(
    x=X.round(2), 
    y=Y.round(2), 
    z=Z.round(2),# plot contour on the plane z=plotz
    surfacecolor=Contour_Val, # use Contour_Val as the surface color

    text=Contour_Val.round(2),
    name='contour',
    
    colorscale='jet',

    showscale=True,
    opacity=0.8,  # <1 to make the contour plane semi-transparent

    hoverinfo='x+y+text+name', # works well

))

fig.show()

Matplotlib version (correct):

Image

Plotly version (wrong):

Image

only those values which form a regular rectangular shape in the matrix are effective in go.Surface plot:

Image

Solution suggestion: Either modify the go.Surface or the go.Contour to make it possible to plot the 2D contour on any plane in a 3D figure.

Hope this issue can be solved together with [#5157] soon. Thanks!

lhg1992 avatar Jun 12 '25 11:06 lhg1992

Thanks for the bug reports @lhg1992 - realistically, it'll be quite some time before we can put someone on these, but I'd be very happy to prioritize review of a PR from the community. Thanks - @gvwilson

gvwilson avatar Jun 13 '25 14:06 gvwilson

Thanks for the bug reports @lhg1992 - realistically, it'll be quite some time before we can put someone on these, but I'd be very happy to prioritize review of a PR from the community. Thanks - @gvwilson

Thanks for your response. I'm really looking forward to it. The go.Surface bugs really stop me from transferring my data visulization code from Matplotlib to Plotly.

lhg1992 avatar Jun 13 '25 17:06 lhg1992

@gvwilson Hi. Same problem encountered (-_-). First time I thought it was an error with my code caused wrong data but finally found it's a BUGrrrr..... I think this issue should correct ASAP.

johnxcutor avatar Jun 16 '25 13:06 johnxcutor

Hello. I also encountered the same problem. I always thought that it was my logic error that caused the data error, but here I found that everyone encountered the same problem. I hope this problem can be solved as soon as possible.

abcdcba123 avatar Jul 28 '25 07:07 abcdcba123

@gvwilson Hello. I also encountered the same problem. I always thought that it was my logic error that caused the data error, but here I found that everyone encountered the same problem. I hope this problem can be solved as soon as possible.

abcdcba123 avatar Jul 28 '25 07:07 abcdcba123

@gvwilson Glad to see Plotly team is now working on this issue. Kindly solve the other issue with the go.Surface together: https://github.com/plotly/plotly.py/issues/5157

lhg1992 avatar Oct 16 '25 05:10 lhg1992