docs: def plotSpikeHist (include = ['allCells', 'eachPop'], timeRange = None, binSize = 5, overlay=True, graphType='line', yaxis = 'rate',
      popColors = [], norm = False, dpi = 100, figSize = (10,8), smooth=None, filtFreq = False, filtOrder=3, axis = 'on', saveData = None,
      saveFig = None, showFig = True, **kwargs):
      '''
      Plot spike histogram
          - include (['all',|'allCells','allNetStims',|,120,|,'E1'|,('L2', 56)|,('L5',[4,5,6])]): List of data series to include.
              Note: one line per item, not grouped (default: ['allCells', 'eachPop'])
          - timeRange ([start:stop]): Time range of spikes shown; if None shows all (default: None)
          - binSize (int): Size in ms of each bin (default: 5)
          - overlay (True|False): Whether to overlay the data lines or plot in separate subplots (default: True)
          - graphType ('line'|'bar'): Type of graph to use (line graph or bar plot) (default: 'line')
          - yaxis ('rate'|'count'): Units of y axis (firing rate in Hz, or spike count) (default: 'rate')
          - popColors (dict): Dictionary with color (value) used for each population (key) (default: None)
          - figSize ((width, height)): Size of figure (default: (10,8))
          - saveData (None|True|'fileName'): File name where to save the final data used to generate the figure;
              if set to True uses filename from simConfig (default: None)
          - saveFig (None|True|'fileName'): File name where to save the figure;
              if set to True uses filename from simConfig (default: None)
          - showFig (True|False): Whether to show the figure or not (default: True)
          - Returns figure handle
      '''
  
      from .. import sim
  
      print('Plotting spike histogram...')
  
      # Replace 'eachPop' with list of pops
      if 'eachPop' in include:
          include.remove('eachPop')
          for pop in sim.net.allPops: include.append(pop)
  
      # Y-axis label
      if yaxis == 'rate':
          if norm:
              yaxisLabel = 'Normalized firing rate'
          else:
              yaxisLabel = 'Avg cell firing rate (Hz)'
      elif yaxis == 'count':
          if norm:
              yaxisLabel = 'Normalized spike count'
          else:
              yaxisLabel = 'Spike count'
      else:
          print('Invalid yaxis value %s', (yaxis))
          return
  
  
      # time range
      if timeRange is None:
          timeRange = [0,sim.cfg.duration]
  
      histData = []
  
      # create fig
      fig,ax1 = plt.subplots(figsize=figSize)
      fontsiz = 12
  
      # Plot separate line for each entry in include
      for iplot,subset in enumerate(include):
          cells, cellGids, netStimLabels = getCellsInclude([subset])
          numNetStims = 0
  
          # Select cells to include
          if len(cellGids) > 0:
              try:
                  spkinds,spkts = list(zip(*[(spkgid,spkt) for spkgid,spkt in zip(sim.allSimData['spkid'],sim.allSimData['spkt']) if spkgid in cellGids]))
              except:
                  spkinds,spkts = [],[]
          else:
              spkinds,spkts = [],[]
  
          # Add NetStim spikes
          spkts, spkinds = list(spkts), list(spkinds)
          numNetStims = 0
          if 'stims' in sim.allSimData:
              for netStimLabel in netStimLabels:
                  netStimSpks = [spk for cell,stims in sim.allSimData['stims'].items() \
                  for stimLabel,stimSpks in stims.items() for spk in stimSpks if stimLabel == netStimLabel]
                  if len(netStimSpks) > 0:
                      lastInd = max(spkinds) if len(spkinds)>0 else 0
                      spktsNew = netStimSpks
                      spkindsNew = [lastInd+1+i for i in range(len(netStimSpks))]
                      spkts.extend(spktsNew)
                      spkinds.extend(spkindsNew)
                      numNetStims += 1
  
          histo = np.histogram(spkts, bins = np.arange(timeRange[0], timeRange[1], binSize))
          histoT = histo[1][:-1]+binSize/2
          histoCount = histo[0]
  
          if yaxis=='rate':
              histoCount = histoCount * (1000.0 / binSize) / (len(cellGids)+numNetStims) # convert to firing rate
  
          if filtFreq:
              from scipy import signal
              fs = 1000.0/binSize
              nyquist = fs/2.0
              if isinstance(filtFreq, list): # bandpass
                  Wn = [filtFreq[0]/nyquist, filtFreq[1]/nyquist]
                  b, a = signal.butter(filtOrder, Wn, btype='bandpass')
              elif isinstance(filtFreq, Number): # lowpass
                  Wn = filtFreq/nyquist
                  b, a = signal.butter(filtOrder, Wn)
              histoCount = signal.filtfilt(b, a, histoCount)
  
          if norm:
              histoCount /= max(histoCount)
  
          if smooth:
              histoCount = _smooth1d(histoCount, smooth)[:len(histoT)]
  
          histData.append(histoCount)
  
          color = popColors[subset] if subset in popColors else colorList[iplot%len(colorList)]
  
          if not overlay:
              plt.subplot(len(include),1,iplot+1)  # if subplot, create new subplot
              plt.title (str(subset), fontsize=fontsiz)
              color = 'blue'
  
          if graphType == 'line':
              plt.plot (histoT, histoCount, linewidth=1.0, color = color)
          elif graphType == 'bar':
              #plt.bar(histoT, histoCount, width = binSize, color = color, fill=False)
              plt.plot (histoT, histoCount, linewidth=1.0, color = color, ls='steps')
  
          if iplot == 0:
              plt.xlabel('Time (ms)', fontsize=fontsiz)
              plt.ylabel(yaxisLabel, fontsize=fontsiz) # add yaxis in opposite side
          plt.xlim(timeRange)
  
      if len(include) < 5:  # if apply tight_layout with many subplots it inverts the y-axis
          try:
              plt.tight_layout()
          except:
              pass
  
      # Add legend
      if overlay:
          for i,subset in enumerate(include):
              color = popColors[subset] if subset in popColors else colorList[i%len(colorList)]
              plt.plot(0,0,color=color,label=str(subset))
          plt.legend(fontsize=fontsiz, bbox_to_anchor=(1.04, 1), loc=2, borderaxespad=0.)
          maxLabelLen = min(10,max([len(str(l)) for l in include]))
          plt.subplots_adjust(right=(0.9-0.012*maxLabelLen))
  
      # Set axis or scaleber
      if axis == 'off':
          ax = plt.gca()
          scalebarLoc = kwargs.get('scalebarLoc', 7)
          round_to_n = lambda x, n, m: int(np.round(round(x, -int(np.floor(np.log10(abs(x)))) + (n - 1)) / m)) * m
          sizex = round_to_n((timeRange[1]-timeRange[0])/10.0, 1, 50)
          add_scalebar(ax, hidex=False, hidey=True, matchx=False, matchy=True, sizex=sizex, sizey=None,
                      unitsx='ms', unitsy='Hz', scalex=1, scaley=1, loc=scalebarLoc, pad=2, borderpad=0.5, sep=4, prop=None, barcolor="black", barwidth=3)
          plt.axis(axis)
  
      # save figure data
      if saveData:
          figData = {'histData': histData, 'histT': histoT, 'include': include, 'timeRange': timeRange, 'binSize': binSize,
           'saveData': saveData, 'saveFig': saveFig, 'showFig': showFig}
  
          _saveFigData(figData, saveData, 'spikeHist')
  
      # save figure
      if saveFig:
          if isinstance(saveFig, basestring):
              filename = saveFig
          else:
              filename = sim.cfg.filename+'_'+'spikeHist.png'
          plt.savefig(filename, dpi=dpi)
  
      # show fig
      if showFig: _showFigure()
  
      return fig, {'include': include, 'histData': histData, 'histoT': histoT, 'timeRange': timeRange}