Exemplo n.º 1
0
    def plot(self,
             vertexcolor=None,
             edgecolor=None,
             vertexsize=None,
             edgewidth=None,
             vertextext=None,
             edgetext=None):
        """Plot a 2D representation of the network.

        Parameters
        ----------
        vertexcolor : dict, optional
            A dictionary mapping vertex identifiers to colors.
        edgecolor : dict, optional
            A dictionary mapping edge identifiers to colors.
        vertexsize : dict, optional
            A dictionary mapping vertex identifiers to sizes.
        edgewidth : dict, optional
            A dictionary mapping edge identifiers to widths.
        vertextext : dict, optional
            A dictionary mappping vertex identifiers to labels.
        edgetext : dict, optional
            A dictionary mappping edge identifiers to labels.

        Examples
        --------
        .. plot::
            :include-source:

            import compas
            from compas.datastructures import Network

            network = Network.from_obj(compas.get('lines.obj'))

            network.plot()

        """
        from compas.plotters import NetworkPlotter

        plotter = NetworkPlotter(self)
        plotter.draw_vertices(facecolor=vertexcolor,
                              radius=vertexsize,
                              text=vertextext)
        plotter.draw_edges(color=edgecolor, width=edgewidth, text=edgetext)
        plotter.show()
Exemplo n.º 2
0
if __name__ == "__main__":

    import compas

    from compas.datastructures import Network
    from compas.plotters import NetworkPlotter

    network = Network.from_obj(compas.get('grid_irregular.obj'))

    plotter = NetworkPlotter(network, figsize=(10, 8))

    plotter.draw_vertices(radius=0.1, picker=10)
    plotter.draw_edges()

    default = [
        plotter.defaults['vertex.facecolor'] for key in network.vertices()
    ]
    highlight = '#ff0000'

    def on_pick(event):
        index = event.ind[0]

        colors = default[:]
        colors[index] = highlight

        plotter.vertexcollection.set_facecolor(colors)
        plotter.update()

    plotter.register_listener(on_pick)
    plotter.show()