Answers for "how to plot side by side bar horizontal bar graph in python"

0

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

import pandas
import matplotlib.pyplot as plt
import numpy as np

df = pandas.DataFrame(dict(graph=['Item one', 'Item two', 'Item three'],
                           n=[3, 5, 2], m=[6, 1, 3])) 

ind = np.arange(len(df))
width = 0.4

fig, ax = plt.subplots()
ax.barh(ind, df.n, width, color='red', label='N')
ax.barh(ind + width, df.m, width, color='green', label='M')

ax.set(yticks=ind + width, yticklabels=df.graph, ylim=[2*width - 1, len(df)])
ax.legend()

plt.show()
Posted by: Guest on August-05-2021

Code answers related to "how to plot side by side bar horizontal bar graph in python"

Python Answers by Framework

Browse Popular Code Answers by Language