281 | def generate_bar_chart(chart_data, bottoms=None, bar_width=0.4, labels=[], orientation='vertical'): |
282 | """ |
283 | Creates a bar chart for revenue using chart_data. |
284 | """ |
285 | fig, ax = plt.subplots(figsize=(12, 6)) |
286 | |
287 | |
288 | indices = np.arange(len(chart_data)) |
289 | |
290 | |
291 | with sb.axes_style('whitegrid'): |
292 | if bottoms is None: |
293 | if orientation == 'horizontal': |
294 | ax.barh(indices, chart_data, height=bar_width, color=PALETTE) |
295 | plt.yticks(indices, labels, rotation=0) |
296 | ax.set_xticklabels(['{:,}'.format(int(x)) for x in ax.get_xticks().tolist()]) |
297 | else: |
298 | ax.bar(indices, chart_data, width=bar_width, color=PALETTE) |
299 | plt.xticks(indices, labels, rotation=0) |
300 | ax.set_yticklabels(['{:,}'.format(int(x)) for x in ax.get_yticks().tolist()]) |
301 | else: |
302 | if orientation == 'horizontal': |
303 | ax.barh(indices, chart_data, left=bottoms, height=bar_width, color=PALETTE) |
304 | plt.yticks(indices, labels, rotation=0) |
305 | ax.set_xticklabels(['{:,}'.format(int(x)) for x in ax.get_xticks().tolist()]) |
306 | |
307 | else: |
308 | ax.bar(indices, chart_data, bottom=bottoms, width=bar_width, color=PALETTE) |
309 | plt.xticks(indices, labels, rotation=0) |
310 | ax.set_yticklabels(['{:,}'.format(int(x)) for x in ax.get_yticks().tolist()]) |
311 | |
312 | |
313 | |
314 | |
315 | return fig, ax |