how to plot side by side bar horizontal bar graph in python

Solutions on MaxInterview for how to plot side by side bar horizontal bar graph in python by the best coders in the world

showing results for - "how to plot side by side bar horizontal bar graph in python"
Eudora
01 Mar 2016
1import pandas
2import matplotlib.pyplot as plt
3import numpy as np
4
5df = pandas.DataFrame(dict(graph=['Item one', 'Item two', 'Item three'],
6                           n=[3, 5, 2], m=[6, 1, 3])) 
7
8ind = np.arange(len(df))
9width = 0.4
10
11fig, ax = plt.subplots()
12ax.barh(ind, df.n, width, color='red', label='N')
13ax.barh(ind + width, df.m, width, color='green', label='M')
14
15ax.set(yticks=ind + width, yticklabels=df.graph, ylim=[2*width - 1, len(df)])
16ax.legend()
17
18plt.show()
19