title: colorbar for a broken bar chart
body: <p>I am totally new to python. I have made a broken bar chart as a subplot.</p>
  
  <p><img src="https://i.stack.imgur.com/aFhCE.png" alt="load profile in matplotlib"></p>
  
  <p>The loads are color coded based on the magnitude of power. Presently, the apha values are provided manually but I can set ranges, say for 0-50, alpha=0.2. Now I want to add a colorbar on the right side. What is the best approach to go ahead? Any help is most welcomed. Please note that this graph is a subplot. Here's my code:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import matplotlib.colors as mcolors
  from matplotlib.figure import Figure
  import matplotlib.cm
  from pylab import *
  import numpy as np
  
  #code for the previous subplots
  
  ax3.set_title('Load Profile')
  ax3.patch.set_facecolor('silver')
  
  barHeight = 3
  ticklist = []
  def drawLoadDuration(period, starty, opacity):
      ax3.broken_barh((period), (starty, barHeight), alpha=opacity, facecolors='#330033', lw=0)
      ticklist.append(starty+barHeight/2.0)
      return 0
  
  drawLoadDuration([(0, 5), (13, 4), (19, 3), (23, 1)], 3, 0.5)   #Fan
  drawLoadDuration([(19, 1)], 9, 0.65)    #Tube Light
  drawLoadDuration([(19, 5)], 15, 0.35)   #Bulb
  drawLoadDuration([(7, 2), (16, 1)], 21, 0.28)   #Charger
  drawLoadDuration([(15, 0.5), (20, 1)], 27, 0.7) #Television
  drawLoadDuration([(9, 1), (17, 1)], 33, 1)  #Pump
  drawLoadDuration([(2,4)], 39, 0.8)    #Scooter
  
  ax3.set_ylim(0, 45)
  ax3.set_xlim(0, 24)
  ax3.set_xlabel('Time (Hours)')
  ax3.set_yticks(ticklist)
  ax3.set_xticks([0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.5, 13, 13.5, 14, 14.5, 15, 15.5, 16, 16.5, 17, 17.5, 18, 18.5, 19, 19.5, 20, 20.5, 21, 21.5, 22, 22.5, 23, 23.5, 24])
  ax3.set_xticklabels(['', '1am', '', '2am', '', '3am', '', '4am', '', '5am', '', '6am', '', '7am', '', '8am', '', '9am', '', '10am', '', '11am', '', '12pm', '', '1pm', '', '2pm', '', '3pm', '', '4pm', '', '5pm', '', '6pm', '', '7pm', '', '8pm', '', '9pm', '', '10pm', '', '11pm', '', '12am'], fontsize='9')
  ax3.tick_params('x', colors='MidnightBlue')
  ax3.set_yticklabels(['Fan', 'Tube light', 'Bulb', 'Cellphone Charger', 'Television', 'Pump', 'Scooter'])
  ax3.grid(True)
  
  f.subplots_adjust(hspace=0.24, right=0.93, left=0.11)
  plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
  </code></pre>