Guest User

Untitled

a guest
Jun 22nd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. def overlapped_bar(df, show=False, width=0.9, alpha=.5,
  2. title='', xlabel='', ylabel='', **plot_kwargs):
  3. """Like a stacked bar chart except bars on top of each other with transparency"""
  4. xlabel = xlabel or df.index.name
  5. N = len(df)
  6. M = len(df.columns)
  7. indices = np.arange(N)
  8. colors = ['steelblue', 'firebrick', 'darksage', 'goldenrod', 'gray'] * int(M / 5. + 1)
  9. for i, label, color in zip(range(M), df.columns, colors):
  10. kwargs = plot_kwargs
  11. kwargs.update({'color': color, 'label': label})
  12. plt.bar(indices, df[label], width=width, alpha=alpha if i else 1, **kwargs)
  13. plt.xticks(indices + .5 * width,
  14. ['{}'.format(idx) for idx in df.index.values])
  15. plt.legend()
  16. plt.title(title)
  17. plt.xlabel(xlabel)
  18. if show:
  19. plt.show()
  20. return plt.gcf()
Add Comment
Please, Sign In to add comment