How to use the nxviz.geometry.get_cartesian 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 / nxviz / plots.py View on Github external
# Define radius 'radius' and circumference 'theta'
            theta = node_theta(self.nodes, node)
            # multiplication factor 1.02 moved below
            radius = self.plot_radius + self.nodeprops["radius"]

            # Coordinates of text inside nodes
            if self.node_label_layout == "numbers":
                radius_adjustment = self.plot_radius / radius
            else:
                radius_adjustment = 1.02
            x, y = get_cartesian(r=radius * radius_adjustment, theta=theta)

            # ----- For numbered nodes -----

            # Node label x-axis coordinate
            tx, _ = get_cartesian(r=radius, theta=theta)
            # Create the quasi-circular positioning on the x axis
            tx *= 1 - np.log(np.cos(theta) * self.nonzero_sign(np.cos(theta)))
            # Move each node a little further away from the circos
            tx += self.nonzero_sign(x)

            # Node label y-axis coordinate numerator
            numerator = radius * (
                theta % (self.nonzero_sign(y) * self.nonzero_sign(x) * np.pi)
            )
            # Node label y-axis coordinate denominator
            denominator = self.nonzero_sign(x) * np.pi
            # Node label y-axis coordinate
            ty = 2 * (numerator / denominator)

            # ----- For rotated nodes -----
github ericmjl / nxviz / nxviz / plots.py View on Github external
elif self.group_label_position == "middle":
            node_idcs = node_idcs.reshape(len(node_idcs), 1)
            node_idcs = np.concatenate((node_idcs[:-1], node_idcs[1:]), axis=1)
            for idx in node_idcs:
                theta1 = group_theta(node_length, idx[0])
                theta2 = group_theta(node_length, idx[1] - 1)
                x, y = get_cartesian(r=radius, theta=(theta1 + theta2) / 2)
                ha, va = text_alignment(x, y)
                xs.append(x)
                ys.append(y)
                has.append(ha)
                vas.append(va)

        elif self.group_label_position == "end":
            for idx in node_idcs[1::]:
                x, y = get_cartesian(
                    r=radius, theta=group_theta(node_length, idx - 1)
                )
                ha, va = text_alignment(x, y)
                xs.append(x)
                ys.append(y)
                has.append(ha)
                vas.append(va)

        self.group_label_coords = {"x": xs, "y": ys}
        self.group_label_aligns = {"has": has, "vas": vas}
        self.groups = groups.keys()
github ericmjl / nxviz / nxviz / circos.py View on Github external
def draw_edges(self):
        """
        Renders edges to the figure.
        """
        for i, (start, end) in enumerate(self.edges):
            start_theta = node_theta(self.nodes, start)
            end_theta = node_theta(self.nodes, end)
            verts = [get_cartesian(self.plot_radius, start_theta),
                     (0, 0),
                     get_cartesian(self.plot_radius, end_theta)]
            codes = [Path.MOVETO, Path.CURVE3, Path.CURVE3]

            path = Path(verts, codes)
            self.edgeprops['facecolor'] = 'none'
            self.edgeprops['edgecolor'] = self.edgecolors[i]
            patch = patches.PathPatch(path, lw=1, **self.edgeprops)
            self.ax.add_patch(patch)
github ericmjl / nxviz / nxviz / hive.py View on Github external
for g, (grp, nodes) in enumerate(self.nodes.items()):
            if self.has_edge_within_group(grp):
                for r, node in enumerate(nodes):
                    theta = g * self.major_angle - self.minor_angle
                    x, y = get_cartesian(r+2, theta)
                    xs[grp]['minus'].append(x)
                    ys[grp]['minus'].append(y)

                    theta = g * self.major_angle + self.minor_angle
                    x, y = get_cartesian(r+2, theta)
                    xs[grp]['plus'].append(x)
                    ys[grp]['plus'].append(y)
            else:
                for r, node in enumerate(nodes):
                    theta = g * self.major_angle
                    x, y = get_cartesian(r+2, theta)
                    xs[grp]['axis'].append(x)
                    ys[grp]['axis'].append(y)
        self.node_coords = dict(x=xs, y=ys)
github ericmjl / nxviz / nxviz / plots.py View on Github external
def draw_edges(self):
        """
        Renders edges to the figure.
        """
        for i, (start, end) in enumerate(self.graph.edges()):
            start_theta = node_theta(self.nodes, start)
            end_theta = node_theta(self.nodes, end)
            verts = [
                get_cartesian(self.plot_radius, start_theta),
                (0, 0),
                get_cartesian(self.plot_radius, end_theta),
            ]
            color = self.edge_colors[i]
            codes = [Path.MOVETO, Path.CURVE3, Path.CURVE3]
            lw = self.edge_widths[i]
            path = Path(verts, codes)
            patch = patches.PathPatch(
                path, lw=lw, edgecolor=color, zorder=1, **self.edgeprops
            )
            self.ax.add_patch(patch)
github ericmjl / nxviz / nxviz / hive.py View on Github external
Computes the positions of each node on the plot.

        Sets the node_coords attribute inherited from BasePlot.
        """
        xs = defaultdict(lambda: defaultdict(list))
        ys = defaultdict(lambda: defaultdict(list))
        for g, (grp, nodes) in enumerate(self.nodes.items()):
            if self.has_edge_within_group(grp):
                for r, node in enumerate(nodes):
                    theta = g * self.major_angle - self.minor_angle
                    x, y = get_cartesian(r+2, theta)
                    xs[grp]['minus'].append(x)
                    ys[grp]['minus'].append(y)

                    theta = g * self.major_angle + self.minor_angle
                    x, y = get_cartesian(r+2, theta)
                    xs[grp]['plus'].append(x)
                    ys[grp]['plus'].append(y)
            else:
                for r, node in enumerate(nodes):
                    theta = g * self.major_angle
                    x, y = get_cartesian(r+2, theta)
                    xs[grp]['axis'].append(x)
                    ys[grp]['axis'].append(y)
        self.node_coords = dict(x=xs, y=ys)
github ericmjl / nxviz / nxviz / circos.py View on Github external
def compute_node_positions(self):
        """
        Uses the get_cartesian function to computes the positions of each node
        in the Circos plot.

        Returns `xs` and `ys`, lists of x- and y-coordinates.
        """
        xs = []
        ys = []
        for node in self.nodes:
            theta = node_theta(self.nodes, node)
            x, y = get_cartesian(self.plot_radius, theta)
            xs.append(x)
            ys.append(y)
        self.node_coords = {'x': xs, 'y': ys}
github ericmjl / nxviz / nxviz / plots.py View on Github external
def draw_edges(self):
        """
        Renders edges to the figure.
        """
        for i, (start, end) in enumerate(self.graph.edges()):
            start_theta = node_theta(self.nodes, start)
            end_theta = node_theta(self.nodes, end)
            verts = [
                get_cartesian(self.plot_radius, start_theta),
                (0, 0),
                get_cartesian(self.plot_radius, end_theta),
            ]
            color = self.edge_colors[i]
            codes = [Path.MOVETO, Path.CURVE3, Path.CURVE3]
            lw = self.edge_widths[i]
            path = Path(verts, codes)
            patch = patches.PathPatch(
                path, lw=lw, edgecolor=color, zorder=1, **self.edgeprops
            )
            self.ax.add_patch(patch)