def LogoOverlay(sites, overlayfile, overlay, nperline, sitewidth, rmargin, logoheight, barheight, barspacing, fix_limits={}, fixlongname=False, overlay_cmap=None, underlay=False, scalebar=False):
if os.path.splitext(overlayfile)[<NUM_LIT:1>] != '<STR_LIT>':<EOL><INDENT>raise ValueError("<STR_LIT>" % overlayfile)<EOL><DEDENT>if not overlay_cmap:<EOL><INDENT>(cmap, mapping_d, mapper) = KyteDoolittleColorMapping()<EOL><DEDENT>else:<EOL><INDENT>mapper = pylab.cm.ScalarMappable(cmap=overlay_cmap)<EOL>cmap = mapper.get_cmap()<EOL><DEDENT>pts_per_inch = <NUM_LIT> <EOL>matplotlib.rc('<STR_LIT:text>', usetex=True)<EOL>matplotlib.rc('<STR_LIT>', labelsize=<NUM_LIT:8>)<EOL>matplotlib.rc('<STR_LIT>', direction='<STR_LIT>')<EOL>matplotlib.rc('<STR_LIT>', direction='<STR_LIT>')<EOL>matplotlib.rc('<STR_LIT>', linewidth=<NUM_LIT:0.5>)<EOL>matplotlib.rc('<STR_LIT>', size=<NUM_LIT:3>)<EOL>matplotlib.rc('<STR_LIT>', size=<NUM_LIT>)<EOL>colorbar_bmargin = <NUM_LIT:20> <EOL>colorbar_tmargin = <NUM_LIT:15> <EOL>nlines = int(math.ceil(len(sites) / float(nperline)))<EOL>lmargin = <NUM_LIT> <EOL>barwidth = nperline * sitewidth<EOL>figwidth = lmargin + rmargin + barwidth<EOL>figheight = nlines * (logoheight + len(overlay) * (barheight +<EOL>barspacing)) + (barheight + colorbar_bmargin + colorbar_tmargin) + (<EOL>int(underlay) * len(overlay) * (barheight + barspacing))<EOL>fig = pylab.figure(figsize=(figwidth / pts_per_inch, figheight / pts_per_inch))<EOL>prop_types = {}<EOL>for (prop_d, shortname, longname) in overlay:<EOL><INDENT>if shortname == longname == '<STR_LIT>':<EOL><INDENT>assert all([(isinstance(prop, str) and len(prop) == <NUM_LIT:1>) for <EOL>prop in prop_d.values()]), '<STR_LIT>'<EOL>proptype = '<STR_LIT>'<EOL>(vmin, vmax) = (<NUM_LIT:0>, <NUM_LIT:1>) <EOL>propcategories = None <EOL><DEDENT>elif all([isinstance(prop, str) for prop in prop_d.values()]):<EOL><INDENT>proptype = '<STR_LIT>'<EOL>propcategories = list(set(prop_d.values()))<EOL>propcategories.sort()<EOL>(vmin, vmax) = (<NUM_LIT:0>, len(propcategories) - <NUM_LIT:1>)<EOL><DEDENT>elif all ([isinstance(prop, (int, float)) for prop in prop_d.values()]):<EOL><INDENT>proptype = '<STR_LIT>'<EOL>propcategories = None<EOL>(vmin, vmax) = (min(prop_d.values()), max(prop_d.values()))<EOL>if vmin >= <NUM_LIT:0> and vmin / float(vmax - vmin) < <NUM_LIT>:<EOL><INDENT>vmin = <NUM_LIT:0.0><EOL>if <NUM_LIT> <= vmax <= <NUM_LIT:1.0>:<EOL><INDENT>vmax = <NUM_LIT:1.0><EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % (shortname, str(prop_d.items())))<EOL><DEDENT>if shortname in fix_limits:<EOL><INDENT>(vmin, vmax) = (min(fix_limits[shortname][<NUM_LIT:0>]), max(fix_limits[shortname][<NUM_LIT:0>]))<EOL><DEDENT>assert vmin < vmax, "<STR_LIT>"<EOL>prop_types[shortname] = (proptype, vmin, vmax, propcategories)<EOL><DEDENT>assert len(prop_types) == len(overlay), "<STR_LIT>"<EOL>prop_image = {}<EOL>for iline in range(nlines):<EOL><INDENT>isites = sites[iline * nperline : min(len(sites), (iline + <NUM_LIT:1>) * nperline)]<EOL>xlength = len(isites) * sitewidth<EOL>logo_ax = pylab.axes([lmargin / figwidth, ((nlines - iline - <NUM_LIT:1>) * (logoheight + len(overlay) * (barspacing + barheight))) / figheight, xlength / figwidth, logoheight / figheight], frameon=False)<EOL>logo_ax.yaxis.set_ticks_position('<STR_LIT:none>')<EOL>logo_ax.xaxis.set_ticks_position('<STR_LIT:none>')<EOL>pylab.yticks([])<EOL>pylab.xlim(<NUM_LIT:0.5>, len(isites) + <NUM_LIT:0.5>)<EOL>pylab.xticks([])<EOL>for (iprop, (prop_d, shortname, longname)) in enumerate(overlay):<EOL><INDENT>(proptype, vmin, vmax, propcategories) = prop_types[shortname]<EOL>prop_ax = pylab.axes([<EOL>lmargin / figwidth, <EOL>((nlines - iline - <NUM_LIT:1>) * (logoheight + <EOL>len(overlay) * (barspacing + barheight)) + <EOL>(<NUM_LIT:1> - int(underlay)) * logoheight + int(underlay) * <EOL>barspacing + iprop * (barspacing + barheight)) <EOL>/ figheight, <EOL>xlength / figwidth, <EOL>barheight / figheight], <EOL>frameon=(proptype != '<STR_LIT>'))<EOL>prop_ax.xaxis.set_ticks_position('<STR_LIT:none>')<EOL>pylab.xticks([])<EOL>pylab.xlim((<NUM_LIT:0>, len(isites)))<EOL>pylab.ylim(-<NUM_LIT:0.5>, <NUM_LIT:0.5>)<EOL>if proptype == '<STR_LIT>':<EOL><INDENT>pylab.yticks([])<EOL>prop_ax.yaxis.set_ticks_position('<STR_LIT:none>')<EOL>for (isite, site) in enumerate(isites):<EOL><INDENT>pylab.text(isite + <NUM_LIT:0.5>, -<NUM_LIT:0.5>, prop_d[site], size=<NUM_LIT:9>, <EOL>horizontalalignment='<STR_LIT>', family='<STR_LIT>')<EOL><DEDENT>continue<EOL><DEDENT>pylab.yticks([<NUM_LIT:0>], [shortname], size=<NUM_LIT:8>)<EOL>prop_ax.yaxis.set_ticks_position('<STR_LIT:left>')<EOL>propdata = pylab.zeros(shape=(<NUM_LIT:1>, len(isites)))<EOL>propdata[ : ] = pylab.nan <EOL>for (isite, site) in enumerate(isites):<EOL><INDENT>if site in prop_d:<EOL><INDENT>if proptype == '<STR_LIT>':<EOL><INDENT>propdata[(<NUM_LIT:0>, isite)] = prop_d[site]<EOL><DEDENT>elif proptype == '<STR_LIT>':<EOL><INDENT>propdata[(<NUM_LIT:0>, isite)] = propcategories.index(prop_d[site])<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>prop_image[shortname] = pylab.imshow(propdata, interpolation='<STR_LIT>', aspect='<STR_LIT>', extent=[<NUM_LIT:0>, len(isites), <NUM_LIT:0.5>, -<NUM_LIT:0.5>], cmap=cmap, vmin=vmin, vmax=vmax)<EOL>pylab.yticks([<NUM_LIT:0>], [shortname], size=<NUM_LIT:8>)<EOL><DEDENT><DEDENT>ncolorbars = len([p for p in prop_types.values() if p[<NUM_LIT:0>] != '<STR_LIT>'])<EOL>if scalebar:<EOL><INDENT>ncolorbars += <NUM_LIT:1><EOL><DEDENT>if ncolorbars == <NUM_LIT:1>:<EOL><INDENT>colorbarwidth = <NUM_LIT><EOL>colorbarspacingwidth = <NUM_LIT:1.0> - colorbarwidth<EOL><DEDENT>elif ncolorbars:<EOL><INDENT>colorbarspacingfrac = <NUM_LIT:0.5> <EOL>colorbarwidth = <NUM_LIT:1.0> / (ncolorbars * (<NUM_LIT:1.0> + colorbarspacingfrac)) <EOL>colorbarspacingwidth = colorbarwidth * colorbarspacingfrac <EOL><DEDENT>ybottom = <NUM_LIT:1.0> - (colorbar_tmargin + barheight) / figheight<EOL>propnames = {}<EOL>icolorbar = -<NUM_LIT:1><EOL>icolorbarshift = <NUM_LIT:0><EOL>while icolorbar < len(overlay):<EOL><INDENT>if icolorbar == -<NUM_LIT:1>:<EOL><INDENT>icolorbar += <NUM_LIT:1><EOL>if scalebar:<EOL><INDENT>(scalebarheight, scalebarlabel) = scalebar<EOL>xleft = (colorbarspacingwidth * <NUM_LIT:0.5> + icolorbar *<EOL>(colorbarwidth + colorbarspacingwidth))<EOL>ytop = <NUM_LIT:1> - colorbar_tmargin / figheight<EOL>scalebarheightfrac = scalebarheight / figheight<EOL>fullfigax = pylab.axes([<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:1>], facecolor=(<NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:0>))<EOL>fullfigax.axvline(x=xleft, ymin=ytop - scalebarheightfrac,<EOL>ymax=ytop, color='<STR_LIT>', linewidth=<NUM_LIT>)<EOL>pylab.text(xleft + <NUM_LIT>, ytop - scalebarheightfrac / <NUM_LIT>,<EOL>scalebarlabel, verticalalignment='<STR_LIT>',<EOL>horizontalalignment='<STR_LIT:left>',<EOL>transform=fullfigax.transAxes)<EOL><DEDENT>continue<EOL><DEDENT>(prop_d, shortname, longname) = overlay[icolorbar]<EOL>icolorbar += <NUM_LIT:1><EOL>(proptype, vmin, vmax, propcategories) = prop_types[shortname]<EOL>if proptype == '<STR_LIT>':<EOL><INDENT>icolorbarshift += <NUM_LIT:1><EOL>continue<EOL><DEDENT>if shortname == longname or not longname:<EOL><INDENT>propname = shortname<EOL><DEDENT>elif fixlongname:<EOL><INDENT>propname = longname<EOL><DEDENT>else:<EOL><INDENT>propname = "<STR_LIT>" % (longname, shortname)<EOL><DEDENT>colorbar_ax = pylab.axes([colorbarspacingwidth * <NUM_LIT:0.5> + (icolorbar - icolorbarshift - int(not bool(scalebar))) * (colorbarwidth + colorbarspacingwidth), ybottom, colorbarwidth, barheight / figheight], frameon=True)<EOL>colorbar_ax.xaxis.set_ticks_position('<STR_LIT>')<EOL>colorbar_ax.yaxis.set_ticks_position('<STR_LIT:none>')<EOL>pylab.xticks([])<EOL>pylab.yticks([])<EOL>pylab.title(propname, size=<NUM_LIT:9>)<EOL>if proptype == '<STR_LIT>':<EOL><INDENT>cb = pylab.colorbar(prop_image[shortname], cax=colorbar_ax, orientation='<STR_LIT>')<EOL>if -<NUM_LIT:0.1> <= vmin <= <NUM_LIT:0> and <NUM_LIT:1.0> <= vmax <= <NUM_LIT>:<EOL><INDENT>cb.set_ticks([<NUM_LIT:0>, <NUM_LIT:0.5>, <NUM_LIT:1>])<EOL>cb.set_ticklabels(['<STR_LIT:0>', '<STR_LIT>', '<STR_LIT:1>'])<EOL><DEDENT>if <NUM_LIT:4> < (vmax - vmin) <= <NUM_LIT:11>:<EOL><INDENT>fixedticks = [itick for itick in range(int(vmin), int(vmax) + <NUM_LIT:1>)]<EOL>cb.set_ticks(fixedticks)<EOL>cb.set_ticklabels([str(itick) for itick in fixedticks])<EOL><DEDENT><DEDENT>elif proptype == '<STR_LIT>':<EOL><INDENT>cb = pylab.colorbar(prop_image[shortname], cax=colorbar_ax, orientation='<STR_LIT>', boundaries=[i for i in range(len(propcategories) + <NUM_LIT:1>)], values=[i for i in range(len(propcategories))])<EOL>cb.set_ticks([i + <NUM_LIT:0.5> for i in range(len(propcategories))])<EOL>cb.set_ticklabels(propcategories)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if shortname in fix_limits:<EOL><INDENT>(ticklocs, ticknames) = fix_limits[shortname]<EOL>cb.set_ticks(ticklocs)<EOL>cb.set_ticklabels(ticknames)<EOL><DEDENT><DEDENT>pylab.savefig(overlayfile, transparent=True)<EOL>
Makes overlay for *LogoPlot*.

    This function creates colored bars overlay bars showing up to two
    properties.
    The trick of this function is to create the bars the right
    size so they align when they overlay the logo plot. 

    CALLING VARIABLES:

    * *sites* : same as the variable of this name used by *LogoPlot*.

    * *overlayfile* is a string giving the name of created PDF file containing
      the overlay. It must end in the extension ``.pdf``.

    * *overlay* : same as the variable of this name used by *LogoPlot*.

    * *nperline* : same as the variable of this name used by *LogoPlot*.

    * *sitewidth* is the width of each site in points.

    * *rmargin* is the right margin in points.

    * *logoheight* is the total height of each logo row in points.

    * *barheight* is the total height of each bar in points.

    * *barspacing* is the vertical spacing between bars in points.

    * *fix_limits* has the same meaning of the variable of this name used by *LogoPlot*.

    * *fixlongname* has the same meaning of the variable of this name used by *LogoPlot*.

    * *overlay_cmap* has the same meaning of the variable of this name used by *LogoPlot*.

    * *underlay* is a bool. If `True`, make an underlay rather than an overlay.

    * *scalebar: if not `False`, is 2-tuple `(scalebarheight, scalebarlabel)`
      where `scalebarheight` is in points.