def draw_tree_metadata(ax, y_posns, metadata_metadata, y_axis_names=None, md_font_size=7):
    """
    Draw metadata columns
    
    params:
        ax: matplotlib axes object to draw in
        y_posns: dict
            map from Phylo tree nodes or clades to y locations
        metadata_metadata: list of TreeMetadata objects
        y_axis_names: set or other collection or None
            if given, any node/clade names listed will be used to label the far side of the y axis
            
            
    """
    # plot metadata as heatmap (using bars())
    labels = []
    bottoms, heights, tops, nodes = [], [], [], []
    for node in y_posns:
        y = y_posns[node]
        top = y + .5
        if node.is_terminal():
            height = 1
            node = node.name
        else:
            height = 2
        nodes.append(node)
        heights.append(height)
        bottom = top - height
        bottoms.append(bottom)
        tops.append(top)
        
    for i, metadata in enumerate(metadata_metadata):
        colors = [metadata.get_item_color(g) for g in nodes]
        _ = ax.bar(i, 
                   height=heights, 
                   width=1, 
                   bottom=bottoms, 
                   ec='grey',
                   linewidth=.1,
                   color=colors)
        labels.append(metadata.label)
    
    # x axis labels
    _ = ax.set_xlim([-1,len(labels)])
    _ = ax.set_xticks(list(range(len(labels))))
    _ = ax.set_xticklabels(labels, rotation=90, fontsize=md_font_size)

    # y axis labels    
    ticks, labels = [], []
    if y_axis_names:
        if isinstance(y_axis_names, dict):
            def get_name(genome):
                return y_axis_names[genome]
        else:
            def get_name(genome):
                return genome
            
        for genome, bottom, top in zip(nodes, bottoms, tops):
            if genome in y_axis_names:
                ticks.append((bottom + top) / 2)
                labels.append(get_name(genome))
    
    _ = ax.yaxis.tick_right()
    _ = ax.set_yticks(ticks)
    _ = ax.set_yticklabels(labels, fontsize=7)