def draw(self, title=None):
        fig = plt.figure()
        ax = plt.gca()

        A = self.to_adjacency_matrix()

        scipy_dendrogram(A, color_threshold=0.7 * max(A[:, 2]))

        ax.spines["bottom"].set_visible(False)
        ax.spines["top"].set_visible(False)
        ax.spines["left"].set_visible(False)
        ax.spines["right"].set_visible(False)

        fig.suptitle(title, fontsize=12)
        plt.show()
Esempio n. 2
0
    def draw(self,
             show=True,
             save=False,
             format="pdf",
             labels=None,
             title=None,
             fontsize=None):
        """Draw the dendrogram using pylab and matplotlib."""
        try:
            from scipy.cluster.hierarchy import dendrogram as scipy_dendrogram
        except ImportError:
            raise ImportError("Scipy not installed, can't draw dendrogram")
        try:
            import pylab
        except ImportError:
            raise ImportError("Pylab not installed, can't draw dendrogram")

        fig = pylab.figure()
        m = self.to_linkage_matrix()
        # default labels are the cluster id's (these must be matched!!)
        d = scipy_dendrogram(m,
                             labels=labels,
                             leaf_font_size=fontsize,
                             color_threshold=0.6 * max(m[:, 2]))
        if title is not None:
            fig.suptitle(title, fontsize=12)
        if show:
            fig.show()
        if save:
            fig.savefig('dendrogram.%s' % (format, ))
Esempio n. 3
0
    def draw(self,
             show=True,
             save=False,
             format="pdf",
             labels=None,
             title=None,
             fontsize=None):
        """Draw the dendrogram using pylab and matplotlib."""
        try:
            from scipy.cluster.hierarchy import dendrogram as scipy_dendrogram
        except ImportError:
            raise ImportError("Scipy not installed, can't draw dendrogram")
        try:
            import pylab
        except ImportError:
            raise ImportError("Pylab not installed, can't draw dendrogram")

        fig = pylab.figure()
        m = numpy.array(self._items[0].adjacency_list(), numpy.dtype('d'))
        m.view('d,d,d,d').sort(order=['f2'], axis=0)
        # default labels are the cluster id's (these must be matched!!)
        d = scipy_dendrogram(m,
                             labels=labels,
                             leaf_font_size=fontsize,
                             color_threshold=0.6 * max(m[:, 2]))
        if title is not None:
            fig.suptitle(title, fontsize=12)
        if show:
            fig.show()
        if save:
            fig.savefig('dendrogram.%s' % (format, ))
Esempio n. 4
0
def dendrogram(path_to_submissions_directory, clustermap):
    output_path = os.path.join(path_to_submissions_directory, 'output')
    linkage_matrix = np.load(os.path.join(output_path, LINKAGE_NAME))
    edit_distances = np.load(os.path.join(output_path, EDITDISTANCE_NAME))
    plt.figure()
    if not clustermap:
        scipy_dendrogram(linkage_matrix)
    else:
        sns.set(font_scale=1.8)
        sns.clustermap(edit_distances,
                       row_linkage=linkage_matrix,
                       col_linkage=linkage_matrix,
                       annot_kws={"size": 16},
                       cmap='YlGnBu')
    output_chart_path = os.path.join(output_path, 'dendrogram.png')
    plt.savefig(output_chart_path)
    click.echo(f'Saved as \'{output_chart_path}\'.')
Esempio n. 5
0
    def draw_scipy_tree(self,
                        corpus,
                        fontsize=5,
                        color_leafs=True,
                        outputfile=None,
                        save=False,
                        show=True,
                        return_svg=True):
        """
        Draw the dendrogram using plain pylab/scipy/matplotlib.
        """
        plt.clf()
        if outputfile:
            outputfile = os.path.expanduser(outputfile)
        fig = plt.figure()
        ax = fig.add_subplot(111, facecolor='white')
        plt.rcParams['font.family'] = 'arial'
        plt.rcParams['font.size'] = 6
        plt.rcParams['lines.linewidth'] = 0.75
        m = self.to_linkage_matrix()
        labels = corpus.titles
        d = scipy_dendrogram(m,
                             labels=labels,
                             leaf_font_size=fontsize,
                             color_threshold=0.7 * max(m[:, 2]),
                             leaf_rotation=180)
        ax = plt.gca()
        for idx, label in enumerate(ax.get_xticklabels()):
            label.set_rotation('vertical')
            label.set_fontname('Arial')
            label.set_fontsize(fontsize)
            if color_leafs:
                label.set_color(
                    plt.cm.get_cmap('nipy_spectral')(corpus.target_ints[idx] /
                                                     10.))

        ax.get_yaxis().set_ticks([])
        ax.spines['right'].set_visible(False)
        ax.spines['top'].set_visible(False)
        ax.spines['bottom'].set_visible(False)
        ax.spines['left'].set_visible(False)
        ax.xaxis.set_ticks_position('bottom')
        plt.xticks(rotation=90)
        plt.tick_params(axis='x', which='both', bottom='off', top='off')
        plt.tick_params(axis='y', which='both', bottom='off', top='off')
        ax.xaxis.grid(False)
        ax.yaxis.grid(False)
        plt.rcParams["figure.facecolor"] = "white"
        plt.rcParams["axes.facecolor"] = "white"
        plt.rcParams["savefig.facecolor"] = "white"
        plt.subplots_adjust(bottom=0.15)
        if save:
            fig.savefig(outputfile)
        if show:
            plt.show()
        if return_svg:
            return plt_fig_to_svg(fig)
    def draw(self, show=True, save=False, format="pdf", labels=None, title=None, fontsize=None):
        """Draw the dendrogram using pylab and matplotlib."""
        try:
            from scipy.cluster.hierarchy import dendrogram as scipy_dendrogram
        except ImportError:
            raise ImportError("Scipy not installed, can't draw dendrogram")
        try:
            import pylab
        except ImportError:
            raise ImportError("Pylab not installed, can't draw dendrogram")
        try:
            import matplotlib.pyplot as plt
        except ImportError:
            raise ImportError("Matplotlib not installed, can't draw dendrogram")

        fig = plt.figure()
        ax = fig.add_subplot(111, axisbg='white')

        plt.rcParams['font.family'] = 'arial'
        plt.rcParams['font.size'] = 6
        plt.rcParams['lines.linewidth'] = 0.75

        m = self.to_linkage_matrix()

        d = scipy_dendrogram(m, labels=labels,
                             leaf_font_size=fontsize,
                             color_threshold=0.7*max(m[:,2]),
                             leaf_rotation=180)

        ax = plt.gca()
        ax_labels = ax.get_xmajorticklabels()+ax.get_ymajorticklabels()
        for i in range(len(ax_labels)):
            ax_labels[i].set_family('arial')

        ax.get_yaxis().set_ticks([])
        ax.spines['right'].set_visible(False)
        ax.spines['top'].set_visible(False)
        ax.spines['bottom'].set_visible(False)
        ax.spines['left'].set_visible(False)
        ax.xaxis.set_ticks_position('bottom')
        plt.xticks(rotation=90)

        plt.tick_params(axis='x', which='both', bottom='off', top='off')
        plt.tick_params(axis='y', which='both', bottom='off', top='off')
        ax.xaxis.grid(False)
        ax.yaxis.grid(False)

        plt.rcParams["figure.facecolor"] = "white"
        plt.rcParams["axes.facecolor"] = "white"
        plt.rcParams["savefig.facecolor"] = "white"

        if title is not None:
            fig.suptitle(title, fontsize=12)
        if show:
            fig.show()
        if save:
            fig.savefig('dendrogram.%s' % (format,))
Esempio n. 7
0
    def draw_scipy_tree(self, corpus, fontsize=5, color_leafs=True,
                        outputfile=None, save=False, show=True, return_svg=True):
        """
        Draw the dendrogram using plain pylab/scipy/matplotlib.
        """
        plt.clf()
        if outputfile:
            outputfile = os.path.expanduser(outputfile)
        fig = sns.plt.figure()
        ax = fig.add_subplot(111, axisbg='white')
        plt.rcParams['font.family'] = 'arial'
        plt.rcParams['font.size'] = 6
        plt.rcParams['lines.linewidth'] = 0.75
        m = self.to_linkage_matrix()
        labels = corpus.titles
        d = scipy_dendrogram(m, labels=labels,
                             leaf_font_size=fontsize,
                             color_threshold=0.7*max(m[:,2]),
                             leaf_rotation=180)
        ax = sns.plt.gca()
        for idx, label in enumerate(ax.get_xticklabels()):
            label.set_rotation('vertical')
            label.set_fontname('Arial')
            label.set_fontsize(fontsize)
            if color_leafs:
                label.set_color(plt.cm.spectral(corpus.target_ints[idx] / 10.))

        ax.get_yaxis().set_ticks([])
        ax.spines['right'].set_visible(False)
        ax.spines['top'].set_visible(False)
        ax.spines['bottom'].set_visible(False)
        ax.spines['left'].set_visible(False)
        ax.xaxis.set_ticks_position('bottom')
        sns.plt.xticks(rotation=90)
        sns.plt.tick_params(axis='x', which='both', bottom='off', top='off')
        sns.plt.tick_params(axis='y', which='both', bottom='off', top='off')
        ax.xaxis.grid(False)
        ax.yaxis.grid(False)
        sns.plt.rcParams["figure.facecolor"] = "white"
        sns.plt.rcParams["axes.facecolor"] = "white"
        sns.plt.rcParams["savefig.facecolor"] = "white"
        sns.plt.subplots_adjust(bottom=0.15)
        if save:
            fig.savefig(outputfile)
        if show:
            sns.plt.show()
        if return_svg:
            return plt_fig_to_svg(fig)
Esempio n. 8
0
    def draw(self, show=True, save=False, format="pdf", labels=None, title=None, fontsize=None):
        """Draw the dendrogram using pylab and matplotlib."""
        try:
            from scipy.cluster.hierarchy import dendrogram as scipy_dendrogram
        except ImportError:
            raise ImportError("Scipy not installed, can't draw dendrogram")
        try:
            import pylab
        except ImportError:
            raise ImportError("Pylab not installed, can't draw dendrogram")

        fig = pylab.figure()
        m = self.to_linkage_matrix()
        # default labels are the cluster id's (these must be matched!!)
        d = scipy_dendrogram(m, labels=labels, leaf_font_size=fontsize,
                             color_threshold=0.6*max(m[:,2]))
        if title is not None:
            fig.suptitle(title, fontsize=12)
        if show:
            fig.show()
        if save:
            fig.savefig('dendrogram.%s' % (format,))
    def draw(self,
             show=True,
             save=False,
             format="pdf",
             labels=None,
             title=None,
             fontsize=None):
        """Draw the dendrogram using pylab and matplotlib."""
        try:
            from scipy.cluster.hierarchy import dendrogram as scipy_dendrogram
        except ImportError:
            raise ImportError("Scipy not installed, can't draw dendrogram")
        try:
            import pylab
        except ImportError:
            raise ImportError("Pylab not installed, can't draw dendrogram")
        try:
            import matplotlib.pyplot as plt
        except ImportError:
            raise ImportError(
                "Matplotlib not installed, can't draw dendrogram")

        fig = plt.figure()
        ax = fig.add_subplot(111, axisbg='white')

        plt.rcParams['font.family'] = 'arial'
        plt.rcParams['font.size'] = 6
        plt.rcParams['lines.linewidth'] = 0.75

        m = self.to_linkage_matrix()

        d = scipy_dendrogram(m,
                             labels=labels,
                             leaf_font_size=fontsize,
                             color_threshold=0.7 * max(m[:, 2]),
                             leaf_rotation=180)

        ax = plt.gca()
        ax_labels = ax.get_xmajorticklabels() + ax.get_ymajorticklabels()
        for i in range(len(ax_labels)):
            ax_labels[i].set_family('arial')

        ax.get_yaxis().set_ticks([])
        ax.spines['right'].set_visible(False)
        ax.spines['top'].set_visible(False)
        ax.spines['bottom'].set_visible(False)
        ax.spines['left'].set_visible(False)
        ax.xaxis.set_ticks_position('bottom')
        plt.xticks(rotation=90)

        plt.tick_params(axis='x', which='both', bottom='off', top='off')
        plt.tick_params(axis='y', which='both', bottom='off', top='off')
        ax.xaxis.grid(False)
        ax.yaxis.grid(False)

        plt.rcParams["figure.facecolor"] = "white"
        plt.rcParams["axes.facecolor"] = "white"
        plt.rcParams["savefig.facecolor"] = "white"

        if title is not None:
            fig.suptitle(title, fontsize=12)
        if show:
            fig.show()
        if save:
            fig.savefig('dendrogram.%s' % (format, ))