Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- numrows = 5
- index = ['A', 'B', 'C', 'D', 'E', 'F']
- test = pd.DataFrame({
- 'Yes': (0.4083, 0.4617, 0.284, 0.607, 0.3634, 0.4075),
- 'No': (0.5875, 0.5383, 0.716, 0.393, 0.635, 0.5925),
- 'Other': (0.00417, 0, 0, 0, 0.0016668,0)},
- index = index)
- def bar_plot(df):
- N = len(df) # number of rows
- ind = np.arange(N)
- width = 0.35
- num_y_cats = len(df.columns)
- p_s = []
- p_s.append(plt.bar(ind, df.iloc[:, 0], width, color='#000000'))
- for i in range(1, len(df.columns)):
- p_s.append(plt.bar(ind, df.iloc[:, i], width, color = ''.join(('#', 6 * str(i))), bottom = np.sum(df.iloc[:,:i], axis=1)))
- plt.ylabel('[%]')
- plt.title('Title')
- x_ticks_names = tuple([item for item in df.index])
- plt.xticks(ind, x_ticks_names)
- plt.yticks(np.arange(0, 1.1, 0.1))
- plt.legend(p_s, df.columns, bbox_to_anchor = (0.5, -0.35), loc = 'lower center', ncol = 3, borderaxespad = 0)
- plt.show()
- plt.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement