def plot(self, form='mass', horizontal_spacing='uniform', color_nodes=[],
             colormap='Dark2'):

        ## Validate inputs
        if not isinstance(color_nodes, list):
            raise TypeError("The 'color_nodes' parameter must be a list.")

        if not set(color_nodes).issubset(self.nodes.keys()):
            raise ValueError("The 'color_nodes' parameter contains values " +
                             "that do not correspond to tree nodes. This " +
                             "tree's node indices are found in the first " +
                             "column of the printed tree.")

        ## Constants
        gap = 0.05
        min_node_width = 1.2

        ## Initialize the plot containers
        node_coords = {}
        split_coords = {}

        ## Find the root connected components and corresponding plot intervals
        ix_root = _np.array([k for k, v in self.nodes.iteritems()
                             if v.parent is None])
        n_root = len(ix_root)
        census = _np.array([len(self.nodes[x].members) for x in ix_root],
                           dtype=_np.float)
        n = sum(census)

        seniority = _np.argsort(census)[::-1]
        ix_root = ix_root[seniority]
        census = census[seniority]

        if horizontal_spacing == 'proportional':
            weights = census / n
            intervals = _np.cumsum(weights)
            intervals = _np.insert(intervals, 0, 0.0)
        else:
            intervals = _np.linspace(0.0, 1.0, n_root + 1)

        ## Do a depth-first search on each root to get segments for each branch
        for i, ix in enumerate(ix_root):
            if form == 'branch-mass':
                branch = self._construct_mass_map(
                    ix, 0.0, (intervals[i], intervals[i + 1]),
                    horizontal_spacing)
            else:
                branch = self._construct_branch_map(
                    ix, (intervals[i], intervals[i + 1]), form,
                    horizontal_spacing, sort=True)

            branch_node_coords, branch_split_coords, _, _ = branch
            node_coords.update(branch_node_coords)
            split_coords.update(branch_split_coords)

        ## Find the fraction of nodes in each segment (to use as line widths)
        node_widths = {k: max(min_node_width, 12.0 * len(node.members) / n)
                       for k, node in self.nodes.items()}

        ## Get the relevant vertical ticks
        primary_ticks = [(x[0][1], x[1][1]) for x in node_coords.values()]
        primary_ticks = _np.unique(_np.array(primary_ticks).flatten())
        primary_labels = [str(round(tick, 2)) for tick in primary_ticks]

        ## Set up the plot framework
        fig, ax = _plt.subplots()
        ax.set_position([0.11, 0.05, 0.78, 0.93])
        ax.set_xlim((-0.04, 1.04))
        ax.set_xticks([])
        ax.set_xticklabels([])
        ax.yaxis.grid(color='gray')
        ax.set_yticks(primary_ticks)
        ax.set_yticklabels(primary_labels)

        ## Form-specific details
        if form == 'branch-mass':
            kappa_max = max(primary_ticks)
            ax.set_ylim((-1.0 * gap * kappa_max, 1.04 * kappa_max))
            ax.set_ylabel("branch mass")

        elif form == 'density':
            ax.set_ylabel("density level")
            ymin = min([v.start_level for v in self.nodes.itervalues()])
            ymax = max([v.end_level for v in self.nodes.itervalues()])
            rng = ymax - ymin
            ax.set_ylim(ymin - gap * rng, ymax + 0.05 * rng)

        elif form == 'mass':
            ax.set_ylabel("mass level")
            ymin = min([v.start_mass for v in self.nodes.itervalues()])
            ymax = max([v.end_mass for v in self.nodes.itervalues()])
            rng = ymax - ymin
            ax.set_ylim(ymin - gap * rng, ymax + 0.05 * ymax)

        else:
            raise ValueError('Plot form not understood')

        ## Color the line segments.
        node_colors = {k: [0.0, 0.0, 0.0, 1.0] for k, v in self.nodes.items()}
        palette = _plt.get_cmap(colormap)
        colorset = palette(_np.linspace(0, 1, len(color_nodes)))

        for i, ix in enumerate(color_nodes):
            subtree = self._make_subtree(ix)

            for ix_sub in subtree.nodes.keys():
                node_colors[ix_sub] = list(colorset[i])

        ## Add the line segments to the figure.
        line_coords = [node_coords[c] for c in node_coords.keys()]
        line_widths = [node_widths[c] for c in node_coords.keys()]
        line_colors = [node_colors[c] for c in node_coords.keys()]

        node_lines = _LineCollection(line_coords, linewidths=line_widths,
                                     colors=line_colors)
        ax.add_collection(node_lines)

        line_coords = [split_coords[c] for c in split_coords.keys()]
        line_colors = [node_colors[c] for c in split_coords.keys()]

        split_lines = _LineCollection(line_coords, colors=line_colors)
        ax.add_collection(split_lines)

        return fig, node_coords, split_coords, node_colors
Plot the level set tree as a dendrogram and return coordinates and
dataset/ETHPy150Open CoAxLab/DeBaCl/debacl/level_set_tree.py/LevelSetTree.plot