title: Arrange bar chart in ascending / descending order
body: <p>I have a random forest feature importance procedure. All the feature importance parameters have been generated for each variable. I have also plotted it on a horizontal bar graph. </p>
  
  <p>Now I would like to sort the bars into ascending / descending order. How do I do it? </p>
  
  <p>My code is as follow:</p>
  
  <pre><code>#Feature Selection (shortlisting key variables)
  
  import numpy as np
  import pandas as pd
  import matplotlib.pyplot as plt
  
  from sklearn.metrics import mean_squared_error
  from sklearn.model_selection import train_test_split
  
  from sklearn.ensemble import RandomForestRegressor
  from sklearn.ensemble import RandomForestClassifier
  from sklearn.feature_selection import SelectFromModel
  from sklearn.metrics import accuracy_score
  
  df = pd.read_excel(r'C:\Users\z003v0ee\Desktop\TP Course\project module\ProjectDataSetrev4.xlsx',sheet_name=0)
  df2 = pd.read_excel(r'C:\Users\z003v0ee\Desktop\TP Course\project module\ProjectDataSetrev4.xlsx',sheet_name=1)
  
  ## Convert date time format and set as index
  df['DateTime']=pd.to_datetime(df['Time Stamp'], format='%Y-%m-%d %H:%M:%S')
  df.set_index(df['DateTime'], inplace=True)
  
  ## Save each feature to a list (independent variables)
  allvarlist = list()
  for each_var in df2.columns:
      allvarlist.append(each_var)
  
  countvar = len(allvarlist)
  allvar = df[allvarlist]
  allvar = allvar.values.reshape(len(allvar),countvar)
  
  ## Define dependent variable
  target = df['(CUP) Chiller Optimization Plant Efficiency [kW/RT]']
  target=target.values.reshape(len(target),1)
  
  ## Split into training and test data
  allvar_train,allvar_test,target_train,target_test= train_test_split(allvar,target, random_state=0, test_size=0.7)
  
  ## Choose a model
  clf = RandomForestRegressor(n_estimators=10000, random_state=0, n_jobs=-1)
  #print(allvar_train)
  #print(target_train)
  
  clf.fit(allvar_train,np.ravel(target_train))
  
  ## Show feature importance results
  for feature in zip(allvarlist, clf.feature_importances_):
      print(feature)
  
  ## Plot feature importance results
  importances = clf.feature_importances_
  #indices = np.argsort(importances)
  
  plt.figure().set_size_inches(14,16)
  plt.barh(range(allvar_train.shape[1]), importances, color="r")
  plt.yticks(range(allvar_train.shape[1]),allvarlist)
  </code></pre>
  
  <p>My graph looks like <a href="https://i.stack.imgur.com/rkZWj.png" rel="noreferrer">this</a>.</p>
  
  <p>Updated code that plots horizontal bar graph:</p>
  
  <pre><code>plt.figure(figsize=(14,16))
  df3=pd.DataFrame({'allvarlist':range(countvar),'importances':allvarlist})
  df3.sort_values('importances',inplace=True)
  df3.plot(kind='barh',y='importances',x='allvarlist',color='r')
  </code></pre>
  
  <p>Still does not work. Error is 'TypeError: Empty 'DataFrame': no numeric data to plot'</p>
  
  <p>Any other suggestions please?</p>