Commit 87ed00ce by Andreas Schmidt

### Move labels to bars in vertical graph.

parent fbf30046
 ... ... @@ -116,6 +116,33 @@ def _plot_controlflow_graph(df, hdb): # print("\t_node__"+edge['Start'] + " -> _node__"+edge['End'] + "[label=\""+str(edge['Correlation'])+"\"];") print("}") # Taken from: http://composition.al/blog/2015/11/29/a-better-way-to-add-labels-to-bar-charts-with-matplotlib/ def autolabel(rects, ax, labels): # Get y-axis height to calculate label position from. (y_bottom, y_top) = ax.get_ylim() y_height = y_top - y_bottom for i, rect in enumerate(rects): height = rect.get_height() color = "black" # Fraction of axis height taken up by this rectangle p_height = (height / y_height) # If we can fit the label above the column, do that; # otherwise, put it inside the column. if p_height > 0.50: # arbitrary; 95% looked good to me. label_position = 0.01 color = "white" else: label_position = height + (y_height * 0.01) ax.text(rect.get_x() + rect.get_width()/2., label_position, labels[i], ha='center', va='bottom', rotation=90, color=color) def _plot_critical_regions(df,hdb): """ plot regions, sorted by latency criticality ... ... @@ -123,18 +150,22 @@ def _plot_critical_regions(df,hdb): for region in sorted(hdb, key = lambda x: -x['Correlation']): print("%-10f %10s -> %10s"%(region['Correlation'], region['Start'], region['End']), file=sys.stderr) relevant = sorted([x for x in hdb if x['Correlation'] > 0], key = lambda x: -x['Correlation']) relevant = sorted([x for x in hdb if x['Correlation'] > 0], key = lambda x: -x['Correlation'], reverse=True) x = np.arange(len(relevant)) bars = plt.bar(x, list(map(lambda x: x['Correlation'], relevant))) correlations = list(map(lambda x: x['Correlation'], relevant)) ticks = list(map(lambda x: "%s-%s" % (x['Start'][:-2], x['End'][:-2]), relevant)) fig, ax = plt.subplots() rects = ax.bar(x, correlations, align="center", tick_label="") autolabel(rects, ax, ticks) # TODO: find a more elegant solution for the label text plt.xticks(x, list(map(lambda x: "%s-%s"%(x['Start'][:-2], x['End'][:-2]) , relevant)), rotation=90) plt.tight_layout() plt.savefig("latency-criticality.png") plt.savefig("latency-criticality.pdf") plt.close() def analyse(df, config): hb = [] for event1 in df: ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment