diff --git a/modules/util/bar_plot.py b/modules/util/bar_plot.py index dd982bd731810717c11eb167421a5ea36eec0892..b7017f8ffae137119d049c1a4a28a2b4b91c9bf7 100644 --- a/modules/util/bar_plot.py +++ b/modules/util/bar_plot.py @@ -2,7 +2,7 @@ import numpy as np import matplotlib.pyplot as plt -def do_plot(group_names, group_values, value_labels, bar_colors, xlabel, ylabel, barWidth=0.1): +def do_plot(group_names, group_values, value_labels, bar_colors, title=None, xlabel=None, ylabel=None, ylim=None, barWidth=0.1): num_groups = len(group_names) num_bars = len(group_values) @@ -11,15 +11,23 @@ def do_plot(group_names, group_values, value_labels, bar_colors, xlabel, ylabel, x = [x + i*barWidth for x in np.arange(num_groups)] bars_x.append(x) + fig, ax = plt.subplots() + if ylim is not None: + ax.set_ylim(ylim) + for k in range(num_bars): plt.bar(bars_x[k], group_values[k], color=bar_colors[k], width=barWidth, edgecolor='white', label=value_labels[k]) # Add xticks on the middle of the group bars - plt.xlabel(xlabel, fontweight='bold') + if xlabel is not None: + plt.xlabel(xlabel, fontweight='bold') plt.xticks([r + barWidth for r in range(num_groups)], group_names) if ylabel is not None: - plt.ylabel('count', fontweight='bold') + plt.ylabel(ylabel, fontweight='bold') + + if title is not None: + plt.title(title, fontweight='bold') # Create legend & Show graphic plt.legend()