✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Hillshade from x y z data

Hello Plotly Community,

I’m trying to create a hillshade. My data set consist of three columns which are longitude latitude and elevation.

I’ve found an example about this topic

plotly - hillshade example

So far i was able to create heatmap version but how can i convert it to hillshade ?

Here’s my example data set;
data

Here’s my code:

import plotly.graph_objects as go
import numpy as np
import scipy.interpolate



x, y, z = np.genfromtxt(r'topo.txt', unpack=True)

N = 250

xi = np.linspace(x.min(), x.max(), N)
yi = np.linspace(y.min(), y.max(), N)
zi = scipy.interpolate.griddata((x, y), z, (xi[None,:], yi[:,None]), method='nearest')


fig= go.Figure(go.Heatmap(x=xi, y=yi, z=zi, colorscale='Earth'))

fig.show()

Update 1

If i use matplotlib lightsource and increase N

import plotly.graph_objects as go
import numpy as np
import scipy.interpolate
from matplotlib.colors import LightSource


x, y, z = np.genfromtxt(r'topo.txt', unpack=True)

N = 750

xi = np.linspace(x.min(), x.max(), N)
yi = np.linspace(y.min(), y.max(), N)
zi = scipy.interpolate.griddata((x, y), z, (xi[None,:], yi[:,None]), method='nearest')


ls = LightSource(azdeg=315, altdeg=45)
hs=ls.hillshade(zi,vert_exag=1)



fig= go.Figure(go.Heatmap(x=xi, y=yi, z=hs,
                         
                        
                         
                        colorscale='Earth',))

fig.show()

It produces something like hillshade but it looks very bad : (

Heatmap Version

Hillshade Version

Hello again,

I am trying to plot something like this.

I made this plot with generic mapping tools. Is it possible to produce it with plotly ?

Best regards.

Hello,

Finally i’ve got my desired output.

There is one more thing i would like to know. My corner coordinates are

28.18 - 28.88 (longitude)
37.50 - 37.88 (latitude)

For example i will add some scatter points (earthquake aftershocks) and their coordinates are

28.50,37.60
28.52,37.56
.
.
.

Is it possible to set my x and y axis values as long lat values ?

import plotly.graph_objects as go
import numpy as np
from matplotlib.colors import LightSource
import matplotlib.pyplot as plt


dem = np.load('topo.npz')
z = dem['elevation']



dx, dy = dem['dx'], dem['dy']
dy = 111200 * dy
dx = 111200 * dx * np.cos(np.radians(dem['ymin']))

ls = LightSource(azdeg=315, altdeg=45)
cmap = plt.cm.gist_earth


rgb = ls.shade(z, cmap=cmap,vmin=0,vmax=2500, blend_mode='overlay',vert_exag=5, dx=dx, dy=dy)

img = np.array((255*rgb[:, :, :3]+0.5), int)
fig= go.Figure(go.Image(z=img ))


fig.show()