예제 #1
0
파일: meshing_ats.py 프로젝트: wk1984/ats
    def plot(self, color=None, ax=None):
        if color is None:
            import colors
            cm = colors.cm_mapper(0, self.num_cells() - 1)
            colors = [cm(i) for i in range(self.num_cells())]
        else:
            colors = color

        verts = [[self.coords[i, 0:2] for i in f] for f in self.conn]
        from matplotlib import collections
        gons = collections.PolyCollection(verts, facecolors=colors)
        from matplotlib import pyplot as plt
        if ax is None:
            fig, ax = plt.subplots(1, 1)
        ax.add_collection(gons)
        ax.autoscale_view()
예제 #2
0
파일: mesh.py 프로젝트: mousta/argiope
 def to_polycollection(self, *args, **kwargs):
   """
   Returns the mesh as matplotlib polygon collection. (tested only for 2D meshes)
   """                          
   from matplotlib import collections
   nodes, elements = self.nodes, self.elements.reset_index()
   verts = []
   index = []
   for etype, group in elements.groupby([("type", "argiope", "")]):
     index += list(group.index)
     nvert = ELEMENTS[etype].nvert
     conn = group.conn.values[:, :nvert].flatten()
     coords = nodes.coords[["x", "y"]].loc[conn].values.reshape(
                                           len(group), nvert, 2)
     verts += list(coords)
   verts = np.array(verts)
   verts= verts[np.argsort(index)]
   return collections.PolyCollection(verts, *args,**kwargs )