# INTERPOLATE ON STL: Plotting scalar field on 50 points on An 70000-points STL surface

**URL:** https://discourse.vtk.org/t/interpolate-on-stl-plotting-scalar-field-on-50-points-on-an-70000-points-stl-surface/450
**Category:** Support
**Created:** [March 11, 2019, 5:25pm UTC](https://discourse.vtk.org/t/interpolate-on-stl-plotting-scalar-field-on-50-points-on-an-70000-points-stl-surface/450 "2019-03-11T17:25:02Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [March 12, 2019, 6:43pm UTC](https://discourse.vtk.org/t/interpolate-on-stl-plotting-scalar-field-on-50-points-on-an-70000-points-stl-surface/450/4 "2019-03-12T18:43:42Z")

</div>

There are a lot of different ways you could resample/interpolate your sparse points onto your surface. Here are a few using `numpy`, `scipy` and `vtki` but you probably want to check out libraries that implement [kriging](https://en.wikipedia.org/wiki/Kriging).

```python
import vtki
import numpy as np
# Load STL file
surface = vtki.read('InterpolatingOnSTL_final.stl')
# Load numpy file
foo = np.loadtxt('points.txt', skiprows=1, delimiter='\t')
lookup = vtki.PolyData(foo[:, 0:3])
lookup.point_arrays['val'] = foo[:,3]
# Inspect the given data
p = vtki.Plotter()
p.add_mesh(surface)
p.add_mesh(lookup, render_points_as_spheres=True, point_size=10)
p.show()

```

 ![download](https://discourse.vtk.org/uploads/default/original/1X/4be7780b021d3b1080ae3398366abcc2631f3384.png)

```python
# Use scipy to run interpolation
from scipy.interpolate import griddata

method = 'linear'
surface.point_arrays[method] = griddata(
    lookup.points, lookup.point_arrays['val'],
    surface.points, method=method)

method = 'nearest'
surface.point_arrays[method] = griddata(
    lookup.points, lookup.point_arrays['val'],
    surface.points, method=method)

# Assisted linear
assisted = surface.point_arrays['linear'].copy()
badi = np.argwhere(np.isnan(assisted))
assisted[badi] = surface.point_arrays['nearest'][badi]
surface.point_arrays['assisted linear'] = assisted

```

```python
# Plot the nearest neighbor interpolated data
p = vtki.Plotter()
p.add_mesh(surface, scalars='nearest')
p.add_mesh(lookup, render_points_as_spheres=True, 
           point_size=10, color='w')
p.show()

```

 ![download](https://discourse.vtk.org/uploads/default/original/1X/777bd54ac9d70d3898705a220a53166c7b4189fb.png)

```python
# Plot the linear interpolated data
p = vtki.Plotter()
p.add_mesh(surface, scalars='linear')
p.add_mesh(lookup, render_points_as_spheres=True, 
           point_size=10, color='w')
p.show()

```

 ![download](https://discourse.vtk.org/uploads/default/original/1X/82765daa9aff0454122d07f1dc0f260cb8b3a9a1.png)

```python
# Plot the assisted linear interpolated data
p = vtki.Plotter()
p.add_mesh(surface, scalars='assisted linear')
p.add_mesh(lookup, render_points_as_spheres=True, 
           point_size=10, color='w')
p.show()

```

 ![download](https://discourse.vtk.org/uploads/default/original/1X/a1831db2bebc733dbea30a7799c83a4a0770397d.png)

---

_[View the full topic](https://discourse.vtk.org/t/interpolate-on-stl-plotting-scalar-field-on-50-points-on-an-70000-points-stl-surface/450)._
