Smooth 3d isosurface with plotly

18 views Asked by At

I'm trying to plot a fairly complicated isosurface with Plotly. The surface is plotted, however there are always two unwanted "holes" in the surface, as shown here:

enter image description here

where the inner sheet and the outer sheet touch. I could increase the density of the mesh, however everything becomes slower. Is there a better solution to improve the isosurface around these critical points?

Here is the code I've been using so far.

import plotly.graph_objects as go
import numpy as np

def determinant(kx,ky,kz,narr):

    if len(set(narr)) == 1:
        return kx**2+ky**2+kz**2-narr[0]**2

    else:
        n1,n2,n3 = narr
        
        return kx**4*n1**2+(ky**2+kz**2-n1**2)*(ky**2*n2**2+(kz**2-n2**2)*n3**2) + kx**2*(ky**2*(n1**2+n2**2)+kz**2*(n1**2+n3**2)-n1**2*(n2**2+n3**2))

narr = np.array([1.,1.5,2.5])
vmax = narr.max()+0.05
vmin = narr.min()+0.05
X, Y, Z = np.mgrid[-vmax:vmax:40j, -vmax:vmax:40j, -vmax:vmax:40j]

values = determinant(X,Y,Z,narr)

fig = go.Figure(data=go.Isosurface(
    x=X.flatten(),
    y=Y.flatten(),
    z=Z.flatten(),
    value=values.flatten(),
    isomin=0,
    isomax=0,
    caps=dict(x_show=False, y_show=False),
    #surface_fill=0.4,
    showscale=False, # remove colorbar
    colorscale='viridis',
    opacity=0.2,
    ))
fig.update_layout(scene = dict(xaxis = dict(nticks=4, range=[-5,5],),
                               yaxis = dict(nticks=4, range=[-5,5],),
                               zaxis = dict(nticks=4, range=[-5,5],),),
    autosize=False,
                  width=800, height=800,
                  margin=dict(l=65, r=50, b=65, t=90))
fig.show()

However,

0

There are 0 answers