Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def overlapped_bar(df, show=False, width=0.9, alpha=.5,
- title='', xlabel='', ylabel='', **plot_kwargs):
- """Like a stacked bar chart except bars on top of each other with transparency"""
- xlabel = xlabel or df.index.name
- N = len(df)
- M = len(df.columns)
- indices = np.arange(N)
- colors = ['steelblue', 'firebrick', 'darksage', 'goldenrod', 'gray'] * int(M / 5. + 1)
- for i, label, color in zip(range(M), df.columns, colors):
- kwargs = plot_kwargs
- kwargs.update({'color': color, 'label': label})
- plt.bar(indices, df[label], width=width, alpha=alpha if i else 1, **kwargs)
- plt.xticks(indices + .5 * width,
- ['{}'.format(idx) for idx in df.index.values])
- plt.legend()
- plt.title(title)
- plt.xlabel(xlabel)
- if show:
- plt.show()
- return plt.gcf()
Add Comment
Please, Sign In to add comment