简体   繁体   中英

How to smooth Plotly 3d surface plot?

I am generating a topography map in Python using the oceansdb module and Plotly. This map however shows a rough interpretation of the topography and I am wondering how I can smooth the map in between points?

This is the code I have tried:

import plotly.graph_objects as go
import oceansdb
import numpy as np 
from scipy.interpolate import griddata

Xa = np.linspace(29.005,29.405,200)
Ya = np.linspace(-93.6683,-93.2683,200)

db = oceansdb.ETOPO()
dcont = db['topography'].extract(lat=Xa, lon=Ya)
depth = dcont['height']

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

I have tried scipy.interpolate.griddata to smooth the plot, but nothing changes in the plot.

I don't think interpolation is what you want, because if you interpolate within noisy points it will still be noisy. The scipy.ndimage library has some nice smoothing algorithms (the one I show is a simple gaussian smoothing).

import plotly.graph_objects as go
import oceansdb
import numpy as np 
import scipy.ndimage

Xa = np.linspace(29.005,29.405,200)
Ya = np.linspace(-93.6683,-93.2683,200)

db = oceansdb.ETOPO()
dcont = db['topography'].extract(lat=Xa, lon=Ya)
depth = dcont['height']

sigma = [4, 4]
print(sigma)
depthSmooth = scipy.ndimage.filters.gaussian_filter(depth, sigma)

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

You can change the sigma value to change how much smoothing is done (greater sigma means more smoothing and the list is [sigmax, sigmay] ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM