def plot_stacked_bar(barDict, ax, labels, colors):
    """
    Plots a stacked barchart with information stored in the bar dictionary
    passed in. This should be in the form 
    {
        numProcesses1 : [val1, ..., valn]
        ...
        numProcessesY : [val1, ..., valn]
    }
    """
    # For the given dictionary get a list of sorted keys
    sortedKeys = sorted(barDict.keys())
    x = range(len(sortedKeys))

    barWidth = 0.9
    barInd = 0
    # For each item in the sorted keys (i.e. for each number of processors)
    for key in sortedKeys:
        bottom = 0.
        valInd = 0
        # For each of the sub-percentages, plot this
        for val in barDict[key]:
            if (barInd == 0):
                ax.bar(barInd, val, bottom=bottom, width=barWidth,
                        align="center", color=colors[valInd],
                        label=labels[valInd])
            else:
                ax.bar(barInd, val, bottom=bottom, width=barWidth,
                        align="center", color=colors[valInd])
            # Update the bottom of the bar
            bottom += val
            valInd += 1
        # Update the index at which we are plotting
        barInd += 1

    ax.set_xticks(x)
    ax.set_xticklabels(sortedKeys)
    ax.legend(loc=1, bbox_to_anchor=(1.1, 1.1))
    return ax