Ejemplo n.º 1
0
    def draw_edges(self,
                   keys=None,
                   width=None,
                   color=None,
                   text=None,
                   textcolor=None,
                   fontsize=None):
        """Draws the mesh edges.

        Parameters
        ----------
        keys : list
            The keys of the edges to plot.
        width : list
            Width of the mesh edges.
        color : list
            Color for the edge lines.
        text : list
            Strings to be displayed on the edges.
        textcolor : list
            Color for the text to be displayed on the edges.
        fontsize : list
            Font size for the text to be displayed on the edges.

        Returns
        -------
        object
            The matplotlib edge collection object.

        """
        keys = keys or list(self.mesh.edges())

        if text == 'key':
            text = {(u, v): '{}-{}'.format(u, v) for u, v in self.mesh.edges()}
        elif text == 'index':
            text = {(u, v): str(index) for index, (u, v) in enumerate(self.mesh.edges())}
        else:
            pass

        widthdict     = valuedict(keys, width, self.defaults['edge.width'])
        colordict     = valuedict(keys, color, self.defaults['edge.color'])
        textdict      = valuedict(keys, text, '')
        textcolordict = valuedict(keys, textcolor, self.defaults['edge.textcolor'])
        fontsizedict  = valuedict(keys, fontsize, self.defaults['edge.fontsize'])

        lines = []
        for u, v in keys:
            lines.append({
                'start'    : self.mesh.vertex_coordinates(u, 'xy'),
                'end'      : self.mesh.vertex_coordinates(v, 'xy'),
                'width'    : widthdict[(u, v)],
                'color'    : colordict[(u, v)],
                'text'     : textdict[(u, v)],
                'textcolor': textcolordict[(u, v)],
                'fontsize' : fontsizedict[(u, v)]
            })

        collection = self.draw_lines(lines)
        self.edgecollection = collection
        return collection
Ejemplo n.º 2
0
    def draw_blocks(self,
                    keys=None,
                    facecolor=None,
                    edgecolor=None,
                    edgewidth=None,
                    textcolor=None,
                    fontsize=None):
        """Draw the blocks of an assembly.

        Notes
        -----
        The blocks are drawn as the boundaing boxes of their vertices.

        """
        keys = keys or list(self.assembly.vertices())

        facecolordict = valuedict(keys, facecolor, self.block_plotter.defaults['face.facecolor'])
        edgecolordict = valuedict(keys, edgecolor, self.block_plotter.defaults['face.edgecolor'])
        edgewidthdict = valuedict(keys, edgewidth, self.block_plotter.defaults['face.edgewidth'])
        textcolordict = valuedict(keys, textcolor, self.block_plotter.defaults['face.textcolor'])
        fontsizedict  = valuedict(keys, fontsize,  self.block_plotter.defaults['face.fontsize'])

        polygons = []
        for key, attr in self.assembly.vertices(True):
            block = self.assembly.blocks[key]
            xyz = block.get_vertices_attributes('xyz')
            box = bounding_box_xy(xyz)
            polygons.append({
                'points': box,
                'edgecolor': edgecolordict[key],
                'edgewidth': edgewidthdict[key],
                'facecolor': facecolordict[key]
            })
        self.draw_polygons(polygons)
Ejemplo n.º 3
0
    def update_vertices(self, radius=None):
        """Updates the plotter vertex collection based on the current state of the mesh.

        Parameters
        ----------
        radius : {float, dict}, optional
            The vertex radius as a single value, which will be applied to all vertices,
            or as a dictionary mapping vertex keys to specific radii.
            Default is the value set in ``self.defaults``.

        Note
        ----
        This function will only work as expected if all vertices were already present in the collection.

        Examples
        --------
        .. code-block:: python

            pass

        """
        radius = valuedict(self.mesh.vertices(), radius, self.defaults['vertex.radius'])
        circles = []
        for key in self.mesh.vertices():
            c = self.mesh.vertex_coordinates(key, 'xy')
            r = radius[key]
            circles.append(Circle(c, r))
        self.vertexcollection.set_paths(circles)
Ejemplo n.º 4
0
 def update_vertices(self, radius=None):
     """Updates the plotter vertex collection based on the mesh."""
     radius = valuedict(self.mesh.vertices(), radius, self.defaults['vertex.radius'])
     circles = []
     for key in self.mesh.vertices():
         c = self.mesh.vertex_coordinates(key, 'xy')
         r = radius[key]
         circles.append(Circle(c, r))
     self.vertexcollection.set_paths(circles)
Ejemplo n.º 5
0
 def update_faces(self, facecolor=None):
     """Updates the plotter face collection based on the mesh."""
     facecolor = valuedict(self.mesh.faces(), facecolor, self.defaults['face.facecolor'])
     polygons = []
     facecolors = []
     for fkey in self.mesh.faces():
         points = self.mesh.face_coordinates(fkey, 'xy')
         polygons.append(Polygon(points))
         facecolors.append(color_to_rgb(facecolor[fkey], normalize=True))
     self.facecollection.set_paths(polygons)
     self.facecollection.set_facecolor(facecolors)
Ejemplo n.º 6
0
 def draw_faces(self, fkeys=None, color=None, alpha=0.5):
     fkeys = fkeys or list(self.datastructure.faces())
     colordict = valuedict(fkeys, color, self.defaults['color.face'])
     faces = []
     for fkey in fkeys:
         faces.append({
             'name': self.datastructure.face_name(fkey),
             'points': self.datastructure.face_coordinates(fkey),
             'color': colordict[fkey],
             'layer': self.layer
         })
     return xdraw_faces(faces, alpha=alpha)
Ejemplo n.º 7
0
 def draw_vertices(self, radius=0.010, keys=None, color=None):
     keys = keys or list(self.datastructure.vertices())
     colordict = valuedict(keys, color, self.defaults['color.vertex'])
     points = []
     for key in keys:
         points.append({
             'pos': self.datastructure.vertex_coordinates(key),
             'name': self.datastructure.vertex_name(key),
             'color': colordict[key],
             'layer': self.layer,
             'radius': radius})
     return xdraw_cubes(points)
Ejemplo n.º 8
0
 def draw_edges(self, width=0.010, keys=None, color=None):
     keys = keys or list(self.datastructure.edges())
     colordict = valuedict(keys, color, self.defaults['color.edge'])
     lines = []
     for u, v in keys:
         lines.append({
             'start': self.datastructure.vertex_coordinates(u),
             'end': self.datastructure.vertex_coordinates(v),
             'color': colordict[(u, v)],
             'name': self.datastructure.edge_name(u, v),
             'width': width,
             'layer': self.layer
         })
     return xdraw_lines(lines)
Ejemplo n.º 9
0
    def draw_vertices(self,
                      keys=None,
                      radius=None,
                      text=None,
                      facecolor=None,
                      edgecolor=None,
                      edgewidth=None,
                      textcolor=None,
                      fontsize=None,
                      picker=None):
        """Draws the network vertices.

        Parameters
        ----------
        keys : list
            The keys of the vertices to plot.
        radius : list
            A list of radii for the vertices.
        text : list
            Strings to be displayed on the vertices.
        facecolor : list
            Color for the vertex circle fill.
        edgecolor : list
            Color for the vertex circle edge.
        edgewidth : list
            Width for the vertex circle edge.
        textcolor : list
            Color for the text to be displayed on the vertices.
        fontsize : list
            Font size for the text to be displayed on the vertices.

        Returns
        -------
        object
            The matplotlib point collection object.

        """
        keys = keys or list(self.datastructure.vertices())

        if text == 'key':
            text = {key: str(key) for key in self.datastructure.vertices()}
        elif text == 'index':
            text = {
                key: str(index)
                for index, key in enumerate(self.datastructure.vertices())
            }
        elif isinstance(text, basestring):
            if text in self.datastructure.default_vertex_attributes:
                default = self.datastructure.default_vertex_attributes[text]
                if isinstance(default, float):
                    text = {
                        key: '{:.1f}'.format(attr[text])
                        for key, attr in self.datastructure.vertices(True)
                    }
                else:
                    text = {
                        key: str(attr[text])
                        for key, attr in self.datastructure.vertices(True)
                    }
        else:
            pass

        radiusdict = valuedict(keys, radius, self.defaults['vertex.radius'])
        textdict = valuedict(keys, text, '')
        facecolordict = valuedict(keys, facecolor,
                                  self.defaults['vertex.facecolor'])
        edgecolordict = valuedict(keys, edgecolor,
                                  self.defaults['vertex.edgecolor'])
        edgewidthdict = valuedict(keys, edgewidth,
                                  self.defaults['vertex.edgewidth'])
        textcolordict = valuedict(keys, textcolor,
                                  self.defaults['vertex.textcolor'])
        fontsizedict = valuedict(keys, fontsize,
                                 self.defaults['vertex.fontsize'])

        points = []
        for key in keys:
            points.append({
                'pos':
                self.datastructure.vertex_coordinates(key, 'xy'),
                'radius':
                radiusdict[key],
                'text':
                textdict[key],
                'facecolor':
                facecolordict[key],
                'edgecolor':
                edgecolordict[key],
                'edgewidth':
                edgewidthdict[key],
                'textcolor':
                textcolordict[key],
                'fontsize':
                fontsizedict[key]
            })

        collection = self.draw_points(points)
        self.vertexcollection = collection

        if picker:
            collection.set_picker(picker)
        return collection
Ejemplo n.º 10
0
    def draw_faces(self,
                   keys=None,
                   text=None,
                   facecolor=None,
                   edgecolor=None,
                   edgewidth=None,
                   textcolor=None,
                   fontsize=None):
        """Draws the mesh faces.

        Parameters
        ----------
        keys : list
            The keys of the edges to plot.
        text : list
            Strings to be displayed on the edges.
        facecolor : list
            Color for the face fill.
        edgecolor : list
            Color for the face edge.
        edgewidth : list
            Width for the face edge.
        textcolor : list
            Color for the text to be displayed on the edges.
        fontsize : list
            Font size for the text to be displayed on the edges.

        Returns
        -------
        object
            The matplotlib face collection object.
        """
        keys = keys or list(self.mesh.faces())

        if text == 'key':
            text = {key: str(key) for key in self.mesh.faces()}
        elif text == 'index':
            text = {key: str(index) for index, key in enumerate(self.mesh.faces())}
        else:
            pass

        textdict      = valuedict(keys, text, '')
        facecolordict = valuedict(keys, facecolor, self.defaults['face.facecolor'])
        edgecolordict = valuedict(keys, edgecolor, self.defaults['face.edgecolor'])
        edgewidthdict = valuedict(keys, edgewidth, self.defaults['face.edgewidth'])
        textcolordict = valuedict(keys, textcolor, self.defaults['face.textcolor'])
        fontsizedict  = valuedict(keys, fontsize, self.defaults['face.fontsize'])

        polygons = []
        for key in keys:
            polygons.append({
                'points'   : self.mesh.face_coordinates(key, 'xy'),
                'text'     : textdict[key],
                'facecolor': facecolordict[key],
                'edgecolor': edgecolordict[key],
                'edgewidth': edgewidthdict[key],
                'textcolor': textcolordict[key],
                'fontsize' : fontsizedict[key]
            })

        collection = self.draw_polygons(polygons)
        self.facecollection = collection
        return collection