def show_cell_clust(cells, cn, mode='vdps', q=6000, fig=1, save="", suf=''): """ cell: i, mode: DistMode, q: DistQ, fig: i, save: DirName, suf: s -> None (draws in matplotlib figure fig, may write a file) Shows the clustering tree (as show_tree) for each stimulus in each condition, and also the clustering diagram. Draws a figure. If save is non-empty, then also writes a file in that directory, named: "c%i_clust_%s%i%s.png" % (cell, mode, int(q),suf) """ d = cells[cn] f = plt.figure(fig) plt.clf() plt.figtext(0, .98, "%s, mode=%s, q=%.2g" % (cn, mode, q), backgroundcolor='white') labs = stimnames(d) a1 = dist_discrim_incond(d['cond1'], mode, q, len(labs)) a2 = dist_discrim_incond(d['cond2'], mode, q, len(labs)) sb = plt.subplot(121) plt.title("Condition 1") im = vis.dot2img(clust.tree2dot(clust.dtree(a1), labs)) plt.imshow(im) sb.yaxis.set_visible(False) sb.xaxis.set_visible(False) sb = plt.subplot(122) plt.title("Condition 2") im = vis.dot2img(clust.tree2dot(clust.dtree(a2), labs)) plt.imshow(im) sb.yaxis.set_visible(False) sb.xaxis.set_visible(False) f.canvas.draw() if save: save = os.path.expanduser(save) fn = os.path.join(save, "%s_clust_%s%i%s.png" % (cn, mode, int(q), suf)) plt.savefig(fn)
def show_tree(t, labs=None, fig=1): """ t: Tree(N) | s, labs: N-[ of s, fig: i -> None (draws in MPL figure fig) Plots an image of tree t made with graphviz. This is a display wrapper for vis.dot2img and clust.anytree2dot. t is an argument for anytree2dot, which currently accepts strings (that are already dot), tuples of the sort returned by clust.mrtree, Pycluster Tree objects, and ZhangShaSha Node objects. PyCluster trees and mrtrees require labs, a list of strings naming the leaves, in order to correctly label the nodes. Dot strings and Nodes ignore the list, since the leaf names are already included. """ dot = clust.anytree2dot(t, labs) f = plt.figure(fig) plt.clf() im = vis.dot2img(dot) plt.imshow(im) a = f.get_axes()[0] a.yaxis.set_visible(False) a.xaxis.set_visible(False) f.canvas.draw()