import StringIO
import matplotlib
matplotlib.use('Agg')
def show(p):
    img = StringIO.StringIO()
    p.savefig(img, format='svg')
    img.seek(0)
    print "%html <div style='width:1000px'>" + img.buf + "</div>"



def plotBarsRYG(df, title, xlabel, thresholds, ylabel='Frequency', countLabel='count', cleanx=True, figSize=(16,4)):
    g_count = 15
    y_count = 30
    r_count = 30
    colors = [['r'] * r_count, ['y'] * y_count, ['g'] * g_count]
    colors = [c for x in colors for c in x]
    f = df.plot(y=countLabel, kind='bar', figsize=figSize, color=colors, width=1.0,linewidth=0)
    if (cleanx):
        f.set_xticklabels([])
        f.axes.get_xaxis().set_ticks([])
    f.legend().remove()
    g = plt.title(title)
    g = plt.xlabel(xlabel)
    g = plt.ylabel(ylabel)
    show(plt)
    return f
