text: #!/usr/bin/env python3
  import json
  import matplotlib.pyplot as plt
  import numpy as np
  import argparse
  from itertools import permutations
  import os
  
  if __name__ == "__main__":
  
      parser = argparse.ArgumentParser(description="Plot relaxation times that "
                                       "have been generated by Phoebe")
      parser.add_argument("INPUT",
                          help="Name of the JSON file with transport coefficients")
      parser.add_argument("xaxis", help="x-axis value to plot against, either n or T")
      parser.add_argument("component",
                          help="Component of transport coefficient tensor. Default=xx",
                          default="xx")
      args = parser.parse_args()
  
      allowedComponents = ["xx","xy","xz","yx","yy","yz","zx","zy","zz"]
      allowedXaxis = ["n","T"]
  
      # load in the json output
      jfileName = args.INPUT
      with open(jfileName) as jfile:
          data = json.load(jfile)
  
      # load in either phonon or electron data
      dataKeys = data.keys()
      if "electricalConductivity" in dataKeys:
          coefficients = ["electricalConductivity",
                          "electronicThermalConductivity",
                          "mobility",
                          "seebeckCoefficient"]
      elif "thermalConductivity" in dataKeys:
          coefficients = ["thermalConductivity"]
      else:
          raise ValueError("no coefficients found in the linked json file")
  
      # set up transport coeff component to be plot
      component = args.component
      if component not in allowedComponents:
          raise ValueError("component is not valid")
      xaxis = args.xaxis
      if xaxis not in allowedXaxis:
          raise ValueError("xaxis value choice must be either n or T")
      def mapCoord(x):
          if x == "x": return 0
          elif x == "y": return 1
          elif x == "z": return 2
          else:
              raise ValueError('component is not "x" "y" or "z"')
      i1 = mapCoord(component[0])
      i2 = mapCoord(component[1])
  
      if xaxis == "T":
          x = np.array(data['temperatures'])
      else:
          x = np.array(data['dopingConcentrations'])
  
      for coefficient in coefficients:
          # unpack the json file
          try:
              y = np.array(data[coefficient])
              # size: (temperature, dim1, dim2)
          except KeyError:
              raise KeyError("{} not found. Are you using the correct input json file?".format(coefficient))
  
          # some work for the y axis label
          if coefficient == "electricalConductivity":
              symbol = r'$\sigma_{{{}}}$'.format(component)
              units = ' [' + data[coefficient+"Unit"] + ']'
          elif coefficient == "mobility":
              symbol = r'$\mu_{{{}}}$'.format(component)
              if data[coefficient+"Unit"] == 'cm^2 / V / s':
                  units = ' [' + r'cm$^2$ / V / s' + ']'
              else:
                  units = ' [' + data[coefficient+"Unit"] + ']'
          elif coefficient == "electronicThermalConductivity":
              symbol = r'$\kappa_{{{}}}$'.format(component)
              units = ' [' + data[coefficient+"Unit"] + ']'
          elif coefficient == "seebeckCoefficient":
              symbol = r'$S_{{{}}}$'.format(component)
              if data[coefficient+"Unit"] == 'muV / K':
                  units = ' [' + r'$\mu$' + 'V / K' + ']'
              else:
                  units = ' [' + data[coefficient+"Unit"] + ']'
  
          # plot the thermal conductivity (here we just plot xx component)
          plt.figure()
          plt.plot(x, y[:,i1,i2], lw=2, mew=1.5, ms=8, marker='o', color='royalblue')
          if xaxis == "T":
              plt.xlabel('Temperature [' + data['temperatureUnit'] + ']',fontsize=12)
          else:
              plt.xlabel('n [' + data['dopingConcentrationUnit'] + ']',fontsize=12)
          plt.ylabel(symbol + units,fontsize=12)
          plt.ylim(None, np.max(y[:,i1,i2])*1.1)
          plt.xlim(None, np.max(x)*1.1)
  
          plt.tight_layout()
  
          # save plot
          plotFileName = os.path.splitext(jfileName)[0]
  
          if coefficient == "electricalConductivity":
              plotFileName += "_elcond_{}.pdf".format(component)
          elif coefficient == "mobility":
              plotFileName += "_mobility_{}.pdf".format(component)
          elif coefficient == "electronicThermalConductivity":
              plotFileName += "_thcond_{}.pdf".format(component)
          elif coefficient == "seebeckCoefficient":
              plotFileName += "_seebeck_{}.pdf".format(component)
  
          plt.savefig(plotFileName)
          # plt.show(block=False)
  
  