How to use the nxviz.plots.BasePlot function in nxviz

To help you get started, we’ve selected a few nxviz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ericmjl / nxviz / tests / test_nxviz.py View on Github external
def test_init_sort_and_group_nodes():
    """
    Tests initialization with sorting and grouping of nodes.

    This tests that the nodes are ordered correctly when first grouped on the
    `node_grouping` key, and then sorted within each group on the `node_order`
    key.
    """
    G = make_graph_for_grouping()  # noqa

    b = BasePlot(graph=G, node_grouping="affiliation", node_order="year")

    assert b.nodes == [
        n
        for n, d in sorted(
            G.nodes(data=True),
            key=lambda x: (x[1]["affiliation"], x[1]["year"]),
        )
github ericmjl / nxviz / tests / test_nxviz.py View on Github external
def test_init_node_colors():
    """
    Check node color initialization.

    Does two checks:
    1. If node_color is not passed in as a keyword argument, check that
       self.node_colors is a list of 'blue', of length (number of nodes).
    2. If node_color is passed in as a keyword argument, check that
       self.node_colors is a list with more than one element.
    """
    G = make_graph_for_grouping()  # noqa
    b = BasePlot(graph=G, node_color="year")
    assert len(set(b.node_colors)) > 1

    G = make_graph_for_grouping()  # noqa
    b = BasePlot(graph=G)
    assert len(set(b.node_colors)) == 1
github ericmjl / nxviz / tests / test_nxviz.py View on Github external
def test_init_group_nodes():
    """
    Tests initialization with grouping of nodes.

    This only tests that the nodes are ordered correctly when sorted on the
    `node_grouping` key.
    """
    G = make_graph_for_grouping()  # noqa
    b = BasePlot(graph=G, node_grouping="affiliation")

    assert b.nodes == [
        n
        for n, d in sorted(
            G.nodes(data=True), key=lambda x: x[1]["affiliation"]
        )
github ericmjl / nxviz / tests / test_nxviz.py View on Github external
def test_init_sort_nodes():
    """
    Tests initialization with sorting of nodes.

    This tests that the nodes are ordered correctly when sorted on the
    "node_order" key.
    """
    G = make_graph_for_grouping()  # noqa

    b = BasePlot(graph=G, node_order="year")

    assert b.nodes == [
        n for n, d in sorted(G.nodes(data=True), key=lambda x: x[1]["year"])
    ]
github ericmjl / nxviz / tests / test_nxviz.py View on Github external
def test_init_edge_colors():
    """
    Check edge color initialization.

    Does two checks:
    1.  If edge_color is passed in as a keyword argument, check that
        self.edge_colors is a list with more than one element.
    2.  If edge_color is not passed in as a keyword argument, check that
        self.edge_colors is a list of 'black', of length 0.
    """
    G = make_graph_for_edges()  # noqa
    b = BasePlot(graph=G, edge_color="weight")
    assert len(set(b.edge_colors)) > 1

    G = make_graph_for_grouping()  # noqa
    b = BasePlot(graph=G)
    assert len(set(b.edge_colors)) == 0
github ericmjl / nxviz / nxviz / plots.py View on Github external
nodes = []
                for key in grp_name:
                    nodes.extend(
                        [
                            n
                            for n, d in sorted(
                                self.graph.nodes(data=True),
                                key=lambda x: x[1][self.node_order],
                            )
                            if key in d.values()
                        ]
                    )
                self.nodes = nodes


class CircosPlot(BasePlot):
    """
    Plotting object for CircosPlot.

    Accepts the following additional arguments apart from the ones in
    `BasePlot`:

    :param node_label_layout: which/whether (a) node layout is used,
        either 'rotation', 'numbers' or None
    :type node_label_layout: `string`

    :param group_label_offset: how much to offset the group labels, so that
        they are not overlapping with node labels.
    :type group_label_offset: `float` or `int`

    :param group_legend: Whether to include the legend of the group labels.
    :type group_legend: `bool`
github ericmjl / nxviz / nxviz / plots.py View on Github external
patch = patches.PathPatch(
                path, lw=lw, edgecolor=color, zorder=1, **self.edgeprops
            )
            self.ax.add_patch(patch)

    def draw(self):
        super(ArcPlot, self).draw()

        left_limit = self.node_sizes[0]
        right_limit = sum(r for r in self.node_sizes)
        xlimits = (-left_limit, right_limit + 1)
        self.ax.set_xlim(*xlimits)
        self.ax.set_ylim(*xlimits)


class GeoPlot(BasePlot):
    """
    Plotting object for GeoPlot.

    User only has to specify the keyword arguments that specify the longitude
    and latittude of a node.
    """

    def __init__(
        self,
        graph,
        node_lat: str,
        node_lon: str,
        backend: str = "matplotlib",
        **kwargs,
    ):
        """
github ericmjl / nxviz / nxviz / plots.py View on Github external
def __init__(
        self,
        graph,
        node_order=None,
        node_size=None,
        node_grouping=None,
        node_color=None,
        edge_width=None,
        edge_color=None,
        data_types=None,
        nodeprops=None,
        edgeprops=None,
    ):

        # Initialize using BasePlot
        BasePlot.__init__(
            self,
            graph,
            node_order=node_order,
            node_size=node_size,
            node_grouping=node_grouping,
            node_color=node_color,
            edge_width=edge_width,
            edge_color=edge_color,
            data_types=data_types,
            nodeprops=nodeprops,
            edgeprops=edgeprops,
        )

        # The following atribute is specific to MatrixPlots
        self.cmap = cmaps["continuous"].mpl_colormap
github ericmjl / nxviz / nxviz / plots.py View on Github external
node_color=None,
        node_labels=None,
        edge_width=None,
        edge_color=None,
        data_types=None,
        nodeprops=None,
        edgeprops=None,
        node_label_color=False,
        group_label_position=None,
        group_label_color=False,
        fontsize=10,
        fontfamily="serif",
        legend_handles=None,
        **kwargs,
    ):
        super(BasePlot, self).__init__()
        # Set graph object
        self.graph = graph
        self.nodes = list(graph.nodes())  # keep track of nodes separately.
        self.edges = list(graph.edges())
        # Set node arrangement
        self.node_order = node_order
        self.node_grouping = node_grouping
        self.group_order = group_order
        self.group_and_sort_nodes()

        # Set node radius
        self.node_size = node_size
        if self.node_size:
            self.node_sizes = []
            self.compute_node_sizes()
        else:
github ericmjl / nxviz / nxviz / plots.py View on Github external
#         self.ax.add_patch(circle)
#
#     def draw_edges(self):
#         """
#         Renders the edges to the figure.
#         """
#         pass
#
#     def draw_edge(self, n1, n2):
#         """
#
#         """
#         pass


class MatrixPlot(BasePlot):
    """
    Plotting object for the MatrixPlot.
    """

    def __init__(
        self,
        graph,
        node_order=None,
        node_size=None,
        node_grouping=None,
        node_color=None,
        edge_width=None,
        edge_color=None,
        data_types=None,
        nodeprops=None,
        edgeprops=None,