Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3.  
  4. numrows = 5
  5. index = ['A', 'B', 'C', 'D', 'E', 'F']
  6. test = pd.DataFrame({
  7. 'Yes': (0.4083, 0.4617, 0.284, 0.607, 0.3634, 0.4075),
  8. 'No': (0.5875, 0.5383, 0.716, 0.393, 0.635, 0.5925),
  9. 'Other': (0.00417, 0, 0, 0, 0.0016668,0)},
  10. index = index)
  11.  
  12. def bar_plot(df):
  13. N = len(df) # number of rows
  14. ind = np.arange(N)
  15. width = 0.35
  16. num_y_cats = len(df.columns)
  17.  
  18. p_s = []
  19. p_s.append(plt.bar(ind, df.iloc[:, 0], width, color='#000000'))
  20. for i in range(1, len(df.columns)):
  21. p_s.append(plt.bar(ind, df.iloc[:, i], width, color = ''.join(('#', 6 * str(i))), bottom = np.sum(df.iloc[:,:i], axis=1)))
  22. plt.ylabel('[%]')
  23. plt.title('Title')
  24. x_ticks_names = tuple([item for item in df.index])
  25. plt.xticks(ind, x_ticks_names)
  26. plt.yticks(np.arange(0, 1.1, 0.1))
  27.  
  28. plt.legend(p_s, df.columns, bbox_to_anchor = (0.5, -0.35), loc = 'lower center', ncol = 3, borderaxespad = 0)
  29. plt.show()
  30. plt.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement