def draw_colorbar(lim, n_cols = 128, cmap = 'cmap', vertical=False, hist=None, linecol = 'cyan'):
    """Draw a colorbar"""
    
    # if you want to draw a vertical color bar
    if vertical:
        left=0
        right=1
        mid=sum(lim)/2.0
        rscript=R.plot([left,right],lim,ylim=lim,xlim=[left,right],tp="n",frame=False, xaxt="n", xlab="", ylab="", main="")
        rscript+=R.polygon([left,right,right,left],[lim[0],lim[0],lim[1],lim[1]])
        vals = linspace(lim[0], lim[1], max(2, n_cols))
        rscript+=R.heatmap_bar(vals, vals, lim, lim, bot=left, top=right, vertical=vertical, cmap=cmap)
    # if you want to draw a horizontal color bar
    else:
        top=1
        bot=0
        mid=sum(lim)/2.0
        rscript=R.plot(lim,[bot,top], xlim=lim, ylim=[bot,top], tp="n", frame=False, yaxt="n", xlab="", ylab="",main='')
        rscript+=R.polygon([lim[0],lim[1],lim[1],lim[0]],[bot,bot,top,top])
        vals = linspace(lim[0], lim[1], max(2, n_cols))  
        rscript+=R.heatmap_bar(vals, vals, lim, lim, bot=bot, top=top, cmap = cmap)
        # if histogram is given
        if hist:
            N = 0.8                         # ratio for normalization
            max_count=max(hist['count'])    # get the maximum count and normalize the other counts with it
            probability = [N * h / max_count for h in hist['count']]    # normalize
            within_lim = arglim(hist['bin'],lim)  # get the index of elements within lim
            bins2draw = array_extractor(hist['bin'], within_lim)    # extract the corresponding bins
            prob2draw = array_extractor(probability, within_lim)    # extract the corresponding probabilities
            rscript += R.lines(bins2draw, prob2draw, col=[linecol], xlim=lim, ylim=[bot, top])  # draw using R.lines
    
    return rscript
dataset/ETHPy150Open taoliu/taolib/Assoc/inout.py/draw_colorbar/original