Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 946ffad

Browse files
committed
Merge pull request #1822 from GBillotey/improved_triinterp_demo
Improved triinterp_demo pylab example
2 parents 91eb1a9 + 6c2b172 commit 946ffad

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

examples/pylab_examples/triinterp_demo.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,44 @@
1414

1515
# Interpolate to regularly-spaced quad grid.
1616
z = np.cos(1.5*x)*np.cos(1.5*y)
17-
interp = mtri.LinearTriInterpolator(triang, z)
1817
xi, yi = np.meshgrid(np.linspace(0, 3, 20), np.linspace(0, 3, 20))
19-
zi = interp(xi, yi)
18+
19+
interp_lin = mtri.LinearTriInterpolator(triang, z)
20+
zi_lin = interp_lin(xi, yi)
21+
22+
interp_cubic_geom = mtri.CubicTriInterpolator(triang, z, kind='geom')
23+
zi_cubic_geom = interp_cubic_geom(xi, yi)
24+
25+
interp_cubic_min_E = mtri.CubicTriInterpolator(triang, z, kind='min_E')
26+
zi_cubic_min_E = interp_cubic_min_E(xi, yi)
27+
2028

2129
# Plot the triangulation.
2230
plt.subplot(221)
2331
plt.tricontourf(triang, z)
2432
plt.triplot(triang, 'ko-')
2533
plt.title('Triangular grid')
2634

27-
# Plot interpolation to quad grid.
35+
# Plot linear interpolation to quad grid.
2836
plt.subplot(222)
29-
plt.contourf(xi, yi, zi)
37+
plt.contourf(xi, yi, zi_lin)
3038
plt.plot(xi, yi, 'k-', alpha=0.5)
3139
plt.plot(xi.T, yi.T, 'k-', alpha=0.5)
32-
plt.title('Linear interpolation')
33-
34-
interp2 = mtri.CubicTriInterpolator(triang, z, kind='geom')
35-
zi2 = interp2(xi, yi)
40+
plt.title("Linear interpolation")
3641

42+
# Plot cubic interpolation to quad grid, kind=geom
3743
plt.subplot(223)
38-
plt.contourf(xi, yi, zi2)
44+
plt.contourf(xi, yi, zi_cubic_geom)
3945
plt.plot(xi, yi, 'k-', alpha=0.5)
4046
plt.plot(xi.T, yi.T, 'k-', alpha=0.5)
41-
plt.title('Cubic interpolation (geom)')
42-
43-
interp3 = mtri.CubicTriInterpolator(triang, z, kind='min_E')
44-
zi3 = interp3(xi, yi)
47+
plt.title("Cubic interpolation,\nkind='geom'")
4548

49+
# Plot cubic interpolation to quad grid, kind=min_E
4650
plt.subplot(224)
47-
plt.contourf(xi, yi, zi3)
51+
plt.contourf(xi, yi, zi_cubic_min_E)
4852
plt.plot(xi, yi, 'k-', alpha=0.5)
4953
plt.plot(xi.T, yi.T, 'k-', alpha=0.5)
50-
plt.title('Cubic interpolation (min_E)')
54+
plt.title("Cubic interpolation,\nkind='min_E'")
5155

56+
plt.tight_layout()
5257
plt.show()

0 commit comments

Comments
 (0)