Beispiel #1
0
 def tripcolor(self, *args, **kwargs):
   import matplotlib.tri
   assert len(args) >= 2
   if numeric.isarray(args[0]) and numeric.isarray(args[1]):
     # args = x, y[, triangles[, mask]], values
     tri = matplotlib.tri.Triangulation(*args[:-1])
     values = args[-1]
   else:
     assert len(args) == 2
     tri, values = args
     if not isinstance(tri, matplotlib.tri.Triangulation):
       tri, edges = triangulate(tri, mergetol)
     if not numeric.isarray(values):
       values = numpy.concatenate(values, axis=0)
   assert len(tri.x) == len(values)
   mask = ~numpy.isfinite(values)
   if mask.any():
     tri.set_mask(mask[tri.triangles].any(axis=1))
     values = values.copy()
     values[mask] = numpy.mean(values[~mask]) #Set masked values to average to not affect color range
   return self._pyplot.tripcolor(tri, values, **kwargs)
Beispiel #2
0
tri = Triangulation(x_outer, y_outer)
ntri = tri.triangles.shape[0]

# example of masking a region from https://matplotlib.org/examples/pylab_examples/tripcolor_demo.html

xmid = x_outer[tri.triangles].mean(axis=1)
ymid = y_outer[tri.triangles].mean(
    axis=1)  # finds the center points of each triangle
mask = np.zeros(ntri, dtype=bool)
i = 0
for x, y in zip(xmid, ymid):
    if not polygon_outer.contains(Point(x, y)):
        mask[i] = True
    i = i + 1
print(mask)
tri.set_mask(mask)

# make graphs

levels = np.arange(-10.05, 10.05, .1)

fig, (ax1, ax2) = plt.subplots(nrows=2)

#ax1.triplot(tri, color='0.7') # if you want to see the triangulation

contours = ax1.tricontour(tri, u2_outer - u3_outer, levels=levels)
print(contours.allsegs)
x, y = contours.allsegs[1][0][0]
ax1.plot(x_outer, y_outer, 'ko', ms=3)
ax1.axis((0, a_out / 2, 0, a_out / 2))