Commit 06f1d772 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Fix graph.

parent 87ed00ce
...@@ -120,27 +120,27 @@ def _plot_controlflow_graph(df, hdb): ...@@ -120,27 +120,27 @@ def _plot_controlflow_graph(df, hdb):
# Taken from: http://composition.al/blog/2015/11/29/a-better-way-to-add-labels-to-bar-charts-with-matplotlib/ # 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): def autolabel(rects, ax, labels):
# Get y-axis height to calculate label position from. # Get y-axis height to calculate label position from.
(y_bottom, y_top) = ax.get_ylim() (x_left, x_right) = ax.get_xlim()
y_height = y_top - y_bottom x_width = x_right - x_left
for i, rect in enumerate(rects): for i, rect in enumerate(rects):
height = rect.get_height() width = rect.get_width()
color = "black" color = "black"
align = "left"
# Fraction of axis height taken up by this rectangle # Fraction of axis height taken up by this rectangle
p_height = (height / y_height) p_width = (width / x_width)
# If we can fit the label above the column, do that; # If we can fit the label above the column, do that;
# otherwise, put it inside the column. # otherwise, put it inside the column.
if p_height > 0.50: # arbitrary; 95% looked good to me. if p_width > 0.50: # arbitrary; 95% looked good to me.
label_position = 0.01 label_position = width - (x_width) + 0.7
color = "white" color = "white"
align = "right"
else: else:
label_position = height + (y_height * 0.01) label_position = width + (x_width * 0.01)
ax.text(rect.get_x() + rect.get_width()/2., label_position, ax.text(label_position, rect.get_y(), labels[i], ha=align, va='bottom', rotation=0, color=color)
labels[i],
ha='center', va='bottom', rotation=90, color=color)
def _plot_critical_regions(df,hdb): def _plot_critical_regions(df,hdb):
...@@ -156,7 +156,7 @@ def _plot_critical_regions(df,hdb): ...@@ -156,7 +156,7 @@ def _plot_critical_regions(df,hdb):
correlations = 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)) ticks = list(map(lambda x: "%s-%s" % (x['Start'][:-2], x['End'][:-2]), relevant))
fig, ax = plt.subplots() fig, ax = plt.subplots()
rects = ax.bar(x, correlations, align="center", tick_label="") rects = ax.barh(x, correlations, align="center", tick_label="")
autolabel(rects, ax, ticks) autolabel(rects, ax, ticks)
# TODO: find a more elegant solution for the label text # TODO: find a more elegant solution for the label text
......
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