def plot_bars(bar_list, tick_labels, tick_positions=None, x_label='', y_label='', title='', legend_names=[], loc=2): # plot values fig = plt.figure() fig.suptitle(title) ax = Subplot(fig, 111) ax = fig.add_subplot(ax) plt.ylabel(y_label) plt.xlabel(x_label) # plot each dataset width = .9/len(bar_list) # the width of the bars ind = np.array(range(len(bar_list[0]))) color_list = ['#a6cee3', '#1f78b4', '#b2df8a', '#33a02c', '#fb9a99', '#e31a1c', '#fdbf6f', '#ff7f00', '#cab2d6', '#6a3d9a', '#ffff99', '#b15928'] recs = [] for i in range(len(bar_list)): recs.append(ax.bar(ind + (width * i), bar_list[i], width, color=color_list[i], linewidth=0)) # calculate where the labels should go if tick_positions is not None: ax.set_xticks(np.array(tick_positions) + .5) else: ax.set_xticks(ind + .5) xtickNames = ax.set_xticklabels(tick_labels) # adjust how the axis shows ax.axis["bottom"].major_ticklabels.set_pad(30) ax.axis["bottom"].label.set_pad(20) ax.axis["bottom"].major_ticklabels.set_rotation(30) ax.axis["bottom"].major_ticks.set_visible(False) ax.axis["top"].set_visible(False) # add a legend if len(legend_names) == len(recs): legend_names = tuple([ln.title() for ln in legend_names]) legend_colors = tuple(r[0] for r in recs) ax.legend( legend_colors, legend_names, frameon=False, loc=loc ) plt.gcf().subplots_adjust(bottom=0.19) # adjust the bottom of the plot plt.show()