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

def barchart(data, labels):
    pos = np.arange(len(data)) + 0.5
plt.barh(pos, data.sort_index(), align='center', height=0.25)
plt.yticks(pos, labels.sort_index())
data1 = pd.DataFrame({'key': list('ABCDE'), 'val': np.random.randn(5)})
new_keys = list('EDACB')
data1['ii'] = [new_keys.index(x) for x in data1.key]
data1 = data1.set_index('ii')
barchart(data1['val'], data1['key'])
plt.show()
How to determine the order of bars in a matplotlib bar chart