Permalink
Browse files

Merge pull request #1822 from GBillotey/improved_triinterp_demo

Improved triinterp_demo pylab example
  • Loading branch information...
2 parents 91eb1a9 + 6c2b172 commit 946ffad5e445a1d605eabfa0851cf51ea47224a7 @ianthomas23 ianthomas23 committed Mar 13, 2013
Showing with 20 additions and 15 deletions.
  1. +20 −15 examples/pylab_examples/triinterp_demo.py
@@ -14,39 +14,44 @@
# Interpolate to regularly-spaced quad grid.
z = np.cos(1.5*x)*np.cos(1.5*y)
-interp = mtri.LinearTriInterpolator(triang, z)
xi, yi = np.meshgrid(np.linspace(0, 3, 20), np.linspace(0, 3, 20))
-zi = interp(xi, yi)
+
+interp_lin = mtri.LinearTriInterpolator(triang, z)
+zi_lin = interp_lin(xi, yi)
+
+interp_cubic_geom = mtri.CubicTriInterpolator(triang, z, kind='geom')
+zi_cubic_geom = interp_cubic_geom(xi, yi)
+
+interp_cubic_min_E = mtri.CubicTriInterpolator(triang, z, kind='min_E')
+zi_cubic_min_E = interp_cubic_min_E(xi, yi)
+
# Plot the triangulation.
plt.subplot(221)
plt.tricontourf(triang, z)
plt.triplot(triang, 'ko-')
plt.title('Triangular grid')
-# Plot interpolation to quad grid.
+# Plot linear interpolation to quad grid.
plt.subplot(222)
-plt.contourf(xi, yi, zi)
+plt.contourf(xi, yi, zi_lin)
plt.plot(xi, yi, 'k-', alpha=0.5)
plt.plot(xi.T, yi.T, 'k-', alpha=0.5)
-plt.title('Linear interpolation')
-
-interp2 = mtri.CubicTriInterpolator(triang, z, kind='geom')
-zi2 = interp2(xi, yi)
+plt.title("Linear interpolation")
+# Plot cubic interpolation to quad grid, kind=geom
plt.subplot(223)
-plt.contourf(xi, yi, zi2)
+plt.contourf(xi, yi, zi_cubic_geom)
plt.plot(xi, yi, 'k-', alpha=0.5)
plt.plot(xi.T, yi.T, 'k-', alpha=0.5)
-plt.title('Cubic interpolation (geom)')
-
-interp3 = mtri.CubicTriInterpolator(triang, z, kind='min_E')
-zi3 = interp3(xi, yi)
+plt.title("Cubic interpolation,\nkind='geom'")
+# Plot cubic interpolation to quad grid, kind=min_E
plt.subplot(224)
-plt.contourf(xi, yi, zi3)
+plt.contourf(xi, yi, zi_cubic_min_E)
plt.plot(xi, yi, 'k-', alpha=0.5)
plt.plot(xi.T, yi.T, 'k-', alpha=0.5)
-plt.title('Cubic interpolation (min_E)')
+plt.title("Cubic interpolation,\nkind='min_E'")
+plt.tight_layout()
plt.show()

0 comments on commit 946ffad

Please sign in to comment.