💸 Reduce costs by consolidating proprietary analytics & reporting software to open-source & Dash.
Challenge us to replace your analytics with Dash and reduce costs.

3D Surface visualization of gridded data

Hello,

I have problems with the visualization of an 3D surface. The underlaying data represents a sphere (at least partial) and comes already in 2D grids for X, Y, Z and an additional value V, which should be plotted as surface color.

Scatter plot of data points:

My first approach to plot them as a surface was

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

which gives this result:


As you can see, the surface is not calculated on the “outside” but filling up the inside. I already tried plotting the data as 3D mesh like this (x,y,z are 2d numpy arrays):

fig = go.Figure(data=[go.Mesh3d(x=x.flatten(), y=y.flatten(), z=z.flatten())])
fig.show()

resulting in this plot

I also played around with some external Delauny interpolation from the scipy package.

Is there a simple way to fix this? Maybe a simple data formatting problem?

Hi @VincentD21,
Coukd you please give more details on your data? What is the shape for the x, y, respectively z, as arrays?
If you provide your data ( uploading them somewhere to be accessed) I could help to detect what’ s going on now, and what you should modify to get the right surface.

Thank you for your quick response.

Here is the data as .csv files:

X: https://www.dropbox.com/s/aqn2x7ss48y07xt/xdat.csv?dl=0
Y: https://www.dropbox.com/s/dknwpx7zys7q6ob/ydat.csv?dl=0
Z: https://www.dropbox.com/s/q8fhfq1rb55rhom/zdat.csv?dl=0

All of them are 121x81 2d arrays and are somehow grid based ( I assumed a meshgrid). As an additional comment, the visualization via Tecplot or Paraview works without any problems.

@VincentD21,

I read your data and reshaped them as arrays of shape (121, 81).

From each array I took the subarrays of shape (25, 25) , flattened each one, and plotted as Scatter3d to check whether data are on a patch of surface or not:

with open('xdat.csv') as f:
    x = [float(s) for line in f.readlines() for s in line[:-1].split(';')]
x=np.array(x).reshape((121, 81))
with open('ydat.csv') as f:
    y = [float(s) for line in f.readlines() for s in line[:-1].split(';')]
y=np.array(y).reshape((121, 81))   

with open('zdat.csv') as f:
    z = [float(s) for line in f.readlines() for s in line[:-1].split(';')]
z=np.array(z).reshape((121, 81))

fig=go.Figure(go.Scatter3d(x=x[:25, :25].flatten(), y=y[:25,:25].flatten(), z=z[:25, :25].flatten(),mode='markers', marker_size=2))

Obviously these points do not lie on a continuous patch of surface as they should be

The surface was discretized in a special way. It seems that these points lie on some curves on the surface, but close points as position in the arrays x, y, z, should be close to each other on the surface too, to be ploted as Plotly surface, but as we can see in this image, they aren’t. :frowning:

@empet,

thank you very much for your help. This gave me the right hint to dig a little bit deeper into the data. Turns out that the converter from which I received the data was buggy. After fixing this everthings works as it should and the data can be simply plotted as a surface.

1 Like