|
14 | 14 |
|
15 | 15 | # Interpolate to regularly-spaced quad grid. |
16 | 16 | z = np.cos(1.5*x)*np.cos(1.5*y) |
17 | | -interp = mtri.LinearTriInterpolator(triang, z) |
18 | 17 | 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 | + |
20 | 28 |
|
21 | 29 | # Plot the triangulation. |
22 | 30 | plt.subplot(221) |
23 | 31 | plt.tricontourf(triang, z) |
24 | 32 | plt.triplot(triang, 'ko-') |
25 | 33 | plt.title('Triangular grid') |
26 | 34 |
|
27 | | -# Plot interpolation to quad grid. |
| 35 | +# Plot linear interpolation to quad grid. |
28 | 36 | plt.subplot(222) |
29 | | -plt.contourf(xi, yi, zi) |
| 37 | +plt.contourf(xi, yi, zi_lin) |
30 | 38 | plt.plot(xi, yi, 'k-', alpha=0.5) |
31 | 39 | 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") |
36 | 41 |
|
| 42 | +# Plot cubic interpolation to quad grid, kind=geom |
37 | 43 | plt.subplot(223) |
38 | | -plt.contourf(xi, yi, zi2) |
| 44 | +plt.contourf(xi, yi, zi_cubic_geom) |
39 | 45 | plt.plot(xi, yi, 'k-', alpha=0.5) |
40 | 46 | 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'") |
45 | 48 |
|
| 49 | +# Plot cubic interpolation to quad grid, kind=min_E |
46 | 50 | plt.subplot(224) |
47 | | -plt.contourf(xi, yi, zi3) |
| 51 | +plt.contourf(xi, yi, zi_cubic_min_E) |
48 | 52 | plt.plot(xi, yi, 'k-', alpha=0.5) |
49 | 53 | 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'") |
51 | 55 |
|
| 56 | +plt.tight_layout() |
52 | 57 | plt.show() |
0 commit comments