code: import numpy as np
  import matplotlib.pyplot as plt
  import matplotlib.colors as colors
  from mpl_toolkits.axes_grid1 import make_axes_locatable
  
  #Key:
  # 1=sandstone  2=c_siltstone   3=f_siltstone 
  # 4=marine_silt_shale 5=mudstone 6=wackestone 7=dolomite
  # 8=packstone 9=bafflestone
  
  
  facies_labels = ['SS', 'CSiS', 'FSiS', 'SiSh', 'MS',
                   'WS', 'D','PS', 'BS']
  
  facies_colors = ['#F4D03F', '#F5B041','#DC7633','#6E2C00', '#1B4F72','#2E86C1', '#AED6F1', '#A569BD', '#196F3D']
  
  #facies_color_map is a dictionary that maps facies labels
  #to their respective colors
  
  
  facies_color_map = {}
  for ind, label in enumerate(facies_labels):
      facies_color_map[label] = facies_colors[ind]
  
      
      
  def label_facies(row, labels):
      return labels[ row['Facies'] -1]
  
  def make_facies_log_plot(logs, facies_colors):
      #make sure logs are sorted by depth
      logs = logs.sort_values(by='Depth')
      cmap_facies = colors.ListedColormap(
              facies_colors[0:len(facies_colors)], 'indexed')
      
      ztop=logs.Depth.min(); zbot=logs.Depth.max()
      
      cluster=np.repeat(np.expand_dims(logs['Facies'].values,1), 100, 1)
      
      f, ax = plt.subplots(nrows=1, ncols=6, figsize=(8, 12))
      ax[0].plot(logs.GR, logs.Depth, '-g')
      ax[1].plot(logs.ILD_log10, logs.Depth, '-')
      ax[2].plot(logs.DeltaPHI, logs.Depth, '-', color='0.5')
      ax[3].plot(logs.PHIND, logs.Depth, '-', color='r')
      ax[4].plot(logs.PE, logs.Depth, '-', color='black')
      im=ax[5].imshow(cluster, interpolation='none', aspect='auto',
                      cmap=cmap_facies,vmin=1,vmax=9)
      
      divider = make_axes_locatable(ax[5])
      cax = divider.append_axes("right", size="20%", pad=0.05)
      cbar=plt.colorbar(im, cax=cax)
      cbar.set_label((17*' ').join([' SS ', 'CSiS', 'FSiS', 
                                  'SiSh', ' MS ', ' WS ', ' D  ', 
                                  ' PS ', ' BS ']))
      cbar.set_ticks(range(0,1)); cbar.set_ticklabels('')
      
      for i in range(len(ax)-1):
          ax[i].set_ylim(ztop,zbot)
          ax[i].invert_yaxis()
          ax[i].grid()
          ax[i].locator_params(axis='x', nbins=3)
      
      ax[0].set_xlabel("GR")
      ax[0].set_xlim(logs.GR.min(),logs.GR.max())
      ax[1].set_xlabel("ILD_log10")
      ax[1].set_xlim(logs.ILD_log10.min(),logs.ILD_log10.max())
      ax[2].set_xlabel("DeltaPHI")
      ax[2].set_xlim(logs.DeltaPHI.min(),logs.DeltaPHI.max())
      ax[3].set_xlabel("PHIND")
      ax[3].set_xlim(logs.PHIND.min(),logs.PHIND.max())
      ax[4].set_xlabel("PE")
      ax[4].set_xlim(logs.PE.min(),logs.PE.max())
      ax[5].set_xlabel('Facies')
      
      ax[1].set_yticklabels([]); ax[2].set_yticklabels([]); ax[3].set_yticklabels([])
      ax[4].set_yticklabels([]); ax[5].set_yticklabels([])
      ax[5].set_xticklabels([])
      f.suptitle('Well: %s'%logs.iloc[0]['WellName'], fontsize=14,y=0.94)
  
  
  def compare_facies_plot(logs, compadre, facies_colors):
      """plot the facies plot as a function of depth for both the prediction
         and the actual lithofacies labels.
      """
     
      #make sure logs are sorted by depth
      logs = logs.sort_values(by='Depth')
      cmap_facies = colors.ListedColormap(
              facies_colors[0:len(facies_colors)], 'indexed')
      
      ztop=logs.Depth.min(); zbot=logs.Depth.max()
      
      cluster1 = np.repeat(np.expand_dims(logs['Facies'].values,1), 100, 1)
      cluster2 = np.repeat(np.expand_dims(logs[compadre].values,1), 100, 1)
      
      f, ax = plt.subplots(nrows=1, ncols=7, figsize=(9, 12))
      ax[0].plot(logs.GR, logs.Depth, '-g')
      ax[1].plot(logs.ILD_log10, logs.Depth, '-')
      ax[2].plot(logs.DeltaPHI, logs.Depth, '-', color='0.5')
      ax[3].plot(logs.PHIND, logs.Depth, '-', color='r')
      ax[4].plot(logs.PE, logs.Depth, '-', color='black')
      im1 = ax[5].imshow(cluster1, interpolation='none', aspect='auto',
                      cmap=cmap_facies,vmin=1,vmax=9)
      im2 = ax[6].imshow(cluster2, interpolation='none', aspect='auto',
                      cmap=cmap_facies,vmin=1,vmax=9)
      
      divider = make_axes_locatable(ax[6])
      cax = divider.append_axes("right", size="20%", pad=0.05)
      cbar=plt.colorbar(im2, cax=cax)
      cbar.set_label((17*' ').join([' SS ', 'CSiS', 'FSiS', 
                                  'SiSh', ' MS ', ' WS ', ' D  ', 
                                  ' PS ', ' BS ']))
      cbar.set_ticks(range(0,1)); cbar.set_ticklabels('')
      
      for i in range(len(ax)-2):
          ax[i].set_ylim(ztop,zbot)
          ax[i].invert_yaxis()
          ax[i].grid()
          ax[i].locator_params(axis='x', nbins=3)
          
      ax[0].set_xlabel("GR")
      ax[0].set_xlim(logs.GR.min(),logs.GR.max())
      ax[1].set_xlabel("ILD_log10")
      ax[1].set_xlim(logs.ILD_log10.min(),logs.ILD_log10.max())
      ax[2].set_xlabel("DeltaPHI")
      ax[2].set_xlim(logs.DeltaPHI.min(),logs.DeltaPHI.max())
      ax[3].set_xlabel("PHIND")
      ax[3].set_xlim(logs.PHIND.min(),logs.PHIND.max())
      ax[4].set_xlabel("PE")
      ax[4].set_xlim(logs.PE.min(),logs.PE.max())
      ax[5].set_xlabel('Facies')
      ax[6].set_xlabel(compadre)
      
      ax[1].set_yticklabels([]); ax[2].set_yticklabels([]); ax[3].set_yticklabels([])
      ax[4].set_yticklabels([]); ax[5].set_yticklabels([])
      ax[5].set_xticklabels([])
      ax[6].set_xticklabels([])
      f.suptitle('Well: %s'%logs.iloc[0]['WellName'], fontsize=14,y=0.94)
  
apis: matplotlib.pyplot.colorbar numpy.expand_dims matplotlib.pyplot.subplots