def plot(data, total, grand_total):

    events = [(e, data[e][0]) for e in data]
    events.sort(key=lambda x: x[1])

    def better_name(n):
        if n in list(better_names.keys()):
            return better_names[n]
        else:
            return n

    names = [e[0] for e in events]
    times = [e[1] for e in events]
    times_percent = [100.0 * t / float(total) for t in times]

    if grand_total is not None:
        comments = ["(%3.1f s, %3.1f%%)" % (time, 100.0 * time / grand_total) for time in times]
    else:
        comments = ["(%3.1f s)" % time for time in times]

    labels = [better_name(name) + " " + comment for name, comment in zip(names, comments)]

    explode = [0.05]*len(times)
    plt.pie(times_percent, autopct="%3.1f%%", labels=labels, colors=colors, startangle=0.0, explode=explode)
    plt.margins(x=0.2, y=0.1)
    plt.axis('equal')