Suppose we read some data into a pandas data frame:
data1 = pd.read_csv(\"data.csv\", \"\\t\")
The content looks like this:
I modified original version of barchart. To specify order of bars I am using index set via ii column:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
def barchart(data, labels):
pos = np.arange(len(data)) + 0.5 # the bar centers on the y axis
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()