def plot_cluster_similarity_matrix(plotdir, plotname, meth1, partition1, meth2, partition2, n_biggest_clusters, title='', debug=False): if debug: print '' print '%s %s' % (meth1, meth2) # partition1 = [['4'], ['7', '8'], ['6', '5'], ['99', '3', '1']] # # partition2 = [['1', '2', '3'], ['4'], ['5', '6'], ['7', '8']] # partition2 = [['3'], ['5'], ['6'], ['7'], ['8'], ['99', '3', '4']] a_cluster_lengths, b_cluster_lengths, smatrix = utils.partition_similarity_matrix(meth1, meth2, partition1, partition2, n_biggest_clusters=n_biggest_clusters, debug=debug) if debug: print 'a_clusters: ', ' '.join([str(l) for l in a_cluster_lengths]) print 'b_clusters: ', ' '.join([str(l) for l in b_cluster_lengths]) fig, ax = plt.subplots() plt.gcf().subplots_adjust(bottom=0.14, left=0.18, right=0.95, top=0.92) ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') data = numpy.array(smatrix) cmap = plt.cm.Blues #cm.get_cmap('jet') cmap.set_under('w') heatmap = ax.pcolor(data, cmap=cmap, vmin=0., vmax=1.) cbar = plt.colorbar(heatmap) ticks = [n - 0.5 for n in range(1, n_biggest_clusters + 1, 2)] xticklabels = [str(int(n + 0.5)) for n in ticks] yticklabels = xticklabels if n_biggest_clusters > 20: modulo = 3 ticks = [ticks[it] for it in range(0, len(ticks), modulo)] xticklabels = [b_cluster_lengths[it] for it in range(0, len(b_cluster_lengths), modulo)] yticklabels = [a_cluster_lengths[it] for it in range(0, len(a_cluster_lengths), modulo)] plt.xticks(ticks, xticklabels) plt.yticks(ticks, yticklabels) mpl.rcParams['text.usetex'] = True mpl.rcParams['text.latex.unicode'] = True def boldify(textstr): textstr = textstr.replace('%', '\%') textstr = textstr.replace('\n', '') return r'\textbf{' + textstr + '}' plt.xlabel(boldify(legends.get(meth2, meth2)) + ' cluster size') # I don't know why it's reversed, it just is plt.ylabel(boldify(legends.get(meth1, meth1)) + ' cluster size') ax.set_xlim(0, n_biggest_clusters) ax.set_ylim(0, n_biggest_clusters) plt.title(title) if not os.path.exists(plotdir): os.makedirs(plotdir) plt.savefig(plotdir + '/' + plotname + '.svg') plt.close()
def plot_cluster_similarity_matrix(plotdir, plotname, meth1, partition1, meth2, partition2, n_biggest_clusters, title='', debug=False): if debug: print '' print '%s %s' % (meth1, meth2) # partition1 = [['4'], ['7', '8'], ['6', '5'], ['99', '3', '1']] # # partition2 = [['1', '2', '3'], ['4'], ['5', '6'], ['7', '8']] # partition2 = [['3'], ['5'], ['6'], ['7'], ['8'], ['99', '3', '4']] a_cluster_lengths, b_cluster_lengths, smatrix = utils.partition_similarity_matrix(meth1, meth2, partition1, partition2, n_biggest_clusters=n_biggest_clusters, debug=debug) if debug: print 'a_clusters: ', ' '.join([str(l) for l in a_cluster_lengths]) print 'b_clusters: ', ' '.join([str(l) for l in b_cluster_lengths]) fig, ax = plt.subplots() plt.gcf().subplots_adjust(bottom=0.14, left=0.18, right=0.95, top=0.92) ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') data = numpy.array(smatrix) cmap = plt.cm.Blues #cm.get_cmap('jet') cmap.set_under('w') heatmap = ax.pcolor(data, cmap=cmap, vmin=0., vmax=1.) cbar = plt.colorbar(heatmap) modulo = 2 if n_biggest_clusters > 20: modulo = 3 ticks = [n - 0.5 for n in range(1, n_biggest_clusters + 1, modulo)] xticklabels = [b_cluster_lengths[it] for it in range(0, len(b_cluster_lengths), modulo)] yticklabels = [a_cluster_lengths[it] for it in range(0, len(a_cluster_lengths), modulo)] plt.xticks(ticks, xticklabels) plt.yticks(ticks, yticklabels) mpl.rcParams['text.usetex'] = True mpl.rcParams['text.latex.unicode'] = True def boldify(textstr): textstr = textstr.replace('%', '\%') textstr = textstr.replace('\n', '') return r'\textbf{' + textstr + '}' plt.xlabel(boldify(legends.get(meth2, meth2)) + ' cluster size') # I don't know why it's reversed, it just is plt.ylabel(boldify(legends.get(meth1, meth1)) + ' cluster size') ax.set_xlim(0, n_biggest_clusters) ax.set_ylim(0, n_biggest_clusters) plt.title(title) if not os.path.exists(plotdir): os.makedirs(plotdir) plt.savefig(plotdir + '/' + plotname + '.svg') plt.close()
def plot_cluster_similarity_matrix(plotdir, plotname, meth1, partition1, meth2, partition2, n_biggest_clusters, title='', debug=False): if debug: print '' print '%s %s' % (meth1, meth2) # partition1 = [['4'], ['7', '8'], ['6', '5'], ['99', '3', '1']] # # partition2 = [['1', '2', '3'], ['4'], ['5', '6'], ['7', '8']] # partition2 = [['3'], ['5'], ['6'], ['7'], ['8'], ['99', '3', '4']] a_cluster_lengths, b_cluster_lengths, smatrix = utils.partition_similarity_matrix(meth1, meth2, partition1, partition2, n_biggest_clusters=n_biggest_clusters, debug=debug) if debug: print 'a_clusters: ', ' '.join([str(l) for l in a_cluster_lengths]) print 'b_clusters: ', ' '.join([str(l) for l in b_cluster_lengths]) fig, ax = plt.subplots() plt.gcf().subplots_adjust(bottom=0.14, left=0.18, right=0.95, top=0.92) ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') data = numpy.array(smatrix) cmap = plt.cm.Blues #cm.get_cmap('jet') cmap.set_under('w') heatmap = ax.pcolor(data, cmap=cmap, vmin=0., vmax=1.) cbar = plt.colorbar(heatmap) ticks = [n - 0.5 for n in range(1, n_biggest_clusters + 1, 2)] xticklabels = [str(int(n + 0.5)) for n in ticks] yticklabels = xticklabels if n_biggest_clusters > 20: modulo = 3 ticks = [ticks[it] for it in range(0, len(ticks), modulo)] xticklabels = [b_cluster_lengths[it] for it in range(0, len(b_cluster_lengths), modulo)] yticklabels = [a_cluster_lengths[it] for it in range(0, len(a_cluster_lengths), modulo)] plt.xticks(ticks, xticklabels) plt.yticks(ticks, yticklabels) plt.xlabel(legends.get(meth2, meth2) + ' cluster size') # I don't know why it's reversed, it just is plt.ylabel(legends.get(meth1, meth1) + ' cluster size') ax.set_xlim(0, n_biggest_clusters) ax.set_ylim(0, n_biggest_clusters) plt.title(title) if not os.path.exists(plotdir + '/plots'): os.makedirs(plotdir + '/plots') plt.savefig(plotdir + '/plots/' + plotname + '.svg') plt.close() check_call(['./bin/makeHtml', plotdir, '2', 'foop', 'svg']) check_call(['./bin/permissify-www', plotdir])