Dendrogram plotting in a loop with scipy.cluster.hierarchy.dendrogram function
<p>I'm trying to build some dendrograms in a loop: in every iteration of this loop Distance Matrix is recalculated. However, figures with dendrogram look like they have some (n) dendrogram on it, where n is number of iteration in loop. How can I 'delete' previous dendrogram?</p>

<p>Here it is the part of script I use:</p>

<pre><code>number = 1
for clique_list in cliq_per_chrom:
    print number
    chrlen = len(clique_list)
    print 'calculating DistMatrix'
    DistMatrix = np.zeros(shape=(chrlen,chrlen))
    #FILLING DISTMATRIX
    for i in range(chrlen):
        for j in range(chrlen):
            if i &lt; j:
                recdistlist = []
                f_clique = clique_list[i].split('\t')
                s_clique = clique_list[j].split('\t')
                for pair_cont in itertools.product(f_clique, s_clique):
                    if pair_cont[0] != pair_cont[1]:
                        recombDistCorr = pair_rec_dist(pair_cont)
                    else:
                        recombDistCorr = 0.0
                    recdistlist.append(recombDistCorr)

                if 'INF' not in recdistlist: 
                    rec_dist_clq = np.mean(recdistlist)
                else:
                    rec_dist_clq = 1.14877996253
                DistMatrix[i][j] = rec_dist_clq
                DistMatrix[j][i] = rec_dist_clq
    #DENDROGRAM BUILDING
    linkage_matrix = linkage(DistMatrix, 'average')
    dend = dendrogram(linkage_matrix,leaf_rotation=90., leaf_font_size=8.)
    plt.title('Hierarchical Clustering Dendrogram of Chromosome'+str(number))
    plt.xlabel('Clique of contigs index')
    plt.ylabel('Distance')
    plt.savefig('Hierarchical Clustering Dendrogram of Chromosome'+str(number)+'.png',dpi=100)
    number +=1
</code></pre>