title: matplotlib bar chart with data frame row names as legend
body: <p>I am trying to set the legend of a bar plot using the values of a pandas dataframe. I searched and could not find a solution, I have used another snippet from SO to annotate the bars. The plot generated shows the bars from the series in different colors as I want and even with the values of the bars. In Excel, e.g., you can have a legend that shows the series values as legend. I am trying to get that functionality here.</p>
  
  <p>Here's a MWE:</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  from pylab import *
  import seaborn, itertools
  seaborn.set()
  
  def flip(items, ncol):
      return itertools.chain(*[items[i::ncol] for i in range(ncol)])
  
  def annotateBars(row, ax=ax):
      if row['A'] &lt; 0.2:
          color = 'black'
          vertalign = 'bottom'
          vertpad = 0.02
      else:
          color = 'white'
          vertalign = 'top'
          vertpad = -0.02
  
      ax.text(row.name, row['A'] + vertpad, "{:.4f}%".format(row['A']),
              zorder=10, rotation=90, color=color,
              horizontalalignment='center',
              verticalalignment=vertalign,
              fontsize=14, weight='heavy')
  
  labels1=["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
  width = 0.75
  my_colors = 'gbkymc'
  arr1 = np.random.random((1, 5))
  arr1_ind = np.arange((arr1.shape[1]))
  df_arr1 = pd.DataFrame(zip(*arr1), index = arr1_ind, columns = ['A'])
  ax = df_arr1.plot(kind='bar', width = 0.85, alpha = 0.5, color = my_colors)
  # plt.xticks(arr1_ind+width/4, arr1_ind)
  
  ax.set_xticks(arr1_ind)
  ax.set_xticklabels([labels1[i] for i in arr1_ind])
  hndls, lbls = ax.get_legend_handles_labels()
  plt.legend(flip(hndls, 2), flip(labels1, 2), loc='best', ncol=2)
  
  junk = df_arr1.apply(annotateBars, ax=ax, axis=1)
  plt.tick_params(
      axis='x',          # changes apply to the x-axis
      which='both',      # both major and minor ticks are affected
      bottom='off',      # ticks along the bottom edge are off
      top='off',         # ticks along the top edge are off
      labelbottom='off') # labels along the bottom edge are off
  plt.tight_layout()
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/00IPc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/00IPc.png" alt="Plot generated showing only the first label"></a></p>