title: Matplotlib bar chart: independently adjust alpha values for specific bars
body: <p>I have a simple bar chart, with labeled bars.  The x-axis moves from past to future dates.  I'd like to use a larger alpha value on the future dates to indicate they values are estimates.  I can't figure out how to adjust alpha.  I found advice to change color with 'get_children()[].set_color() This is an OK work around, but I'd like to vary alpha such to have a better color match.  I also tried using a list of alpha values and creating the bars in a for loop.  This worked but I lost the labeling.</p>
  <pre><code>import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  import matplotlib.patches as mpatches
  
  fig, ax = plt.subplots(figsize=(11,6))
  
  req = [700, 600, 500, 450, 350, 300, 200, 150, 100, 50]
  completed = [100, 100, 50, 100, 50, 100, 50, 50,50, 50]
  Months=['May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec', 'Jan-21', 'Feb']
  
  x = np.arange(len(req))  # the label locations
  width = 0.4  # the width of the bars
  
  #I got this to work using a for look on rects but then lost my 'autolabels'
  #alphas_o=([.9, .9, .9, .9, .9, .9, .9, .5, .5, .5])
  #alphas_c=([.9, .9, .9, .9, .9, .9, .5, .5, .5, .5])
  
  
  rects1 = ax.bar(x - width/2, req, width, color='tab:orange', alpha = .9)
  rects2 = ax.bar(x + width/2, completed, width, color='tab:blue', alpha =.9 )
  
  #This is an OK work around, but changing alpha instead of color looks better
  ax.get_children()[7].set_color('moccasin') 
  ax.get_children()[8].set_color('moccasin') 
  ax.get_children()[9].set_color('moccasin') 
  
  ax.get_children()[16].set_color('lightsteelblue') 
  ax.get_children()[17].set_color('lightsteelblue')
  ax.get_children()[18].set_color('lightsteelblue')
  ax.get_children()[19].set_color('lightsteelblue')
  
  
  ax.set_ylabel('Counts',fontsize=12 )
  ax.set_xticks(x)
  ax.set_xticklabels(Months, fontsize=12)
  
  #I put this legend in place when I used the for loop and list of alphas.  It works fine 
  orange_patch = mpatches.Patch(color='tab:orange', label='Total Open Requests')
  blue_patch = mpatches.Patch(color='tab:blue', label='Completed Requests')
  ax.legend(handles=[orange_patch, blue_patch],  frameon=False, fontsize=12, bbox_to_anchor=(.9, .8))
  
  
  def autolabel(rects):
      &quot;&quot;&quot;Attach a text label above each bar in *rects*, displaying its height.&quot;&quot;&quot;
      for rect in rects:
          height = rect.get_height()
          ax.annotate('{}'.format(height),
                      xy=(rect.get_x() + rect.get_width() / 2, height),
                      xytext=(0, 3),  # 3 points vertical offset
                      textcoords=&quot;offset points&quot;,
                      ha='center', va='bottom')
  
  autolabel(rects1)
  autolabel(rects2)
  
  fig.tight_layout()
  
  ax.tick_params(which='both',axis='y', left=False, right=False, labelleft=False, labelright=False)
  
  # remove the frame of the chart
  for spine in plt.gca().spines.values():
      spine.set_visible(False)
  
  plt.show()
  </code></pre>