docs: def nodal_gen_dispatch(
          network,
          networkB=None,
          techs=['wind_onshore', 'solar'],
          item='energy',
          direction=None,
          scaling=1,
          filename=None):
      """
      Plot nodal dispatch or capacity. If networkB is given, difference in
      dispatch is plotted.
      
      Parameters
      ----------
      network : PyPSA network container
          Holds topology of grid including results from powerflow analysis
      networkB : PyPSA network container
          If given and item is 'energy', difference in dispatch between network 
          and networkB is plotted. If item is 'capacity', networkB is ignored.
          default None
      techs : None or list, 
          Techs to plot. If None, all techs are plotted.
          default ['wind_onshore', 'solar']
      item : str
          Specifies the plotted item. Options are 'energy' and 'capacity'.
          default 'energy'
      direction : str
          Only considered if networkB is given and item is 'energy'. Specifies
          the direction of change in dispatch between network and networkB.
          If 'positive', generation per tech which is higher in network than in 
          networkB is plotted.
          If 'negative', generation per tech whcih is lower in network than 
          in networkB is plotted.
          If 'absolute', total change per node is plotted. 
          Green nodes have higher dispatch in network than in networkB.
          Red nodes have lower dispatch in network than in networkB.
          default None
      scaling : int
          Scaling to change plot sizes.
          default 1
      filename : path to folder
      """   
      
      if techs:
          gens = network.generators[network.generators.carrier.isin(techs)]
      elif techs is None:
          gens = network.generators
          techs = gens.carrier.unique()
      if item == 'capacity':
          dispatch = gens.p_nom.groupby([network.generators.bus, 
                                              network.generators.carrier]).sum()
      elif item == 'energy':
          if networkB:
              dispatch_network =\
                      network.generators_t.p[gens.index].mul(
                              network.snapshot_weightings, axis=0).groupby(
                      [network.generators.bus, network.generators.carrier], 
                      axis=1).sum()
              dispatch_networkB =\
                      networkB.generators_t.p[gens.index].mul(
                              networkB.snapshot_weightings, axis=0).groupby(
                      [networkB.generators.bus, networkB.generators.carrier], 
                      axis=1).sum()
              dispatch = dispatch_network - dispatch_networkB
              
              if direction == 'positive':
                  dispatch = dispatch[dispatch > 0].fillna(0)
              elif direction == 'negative':
                  dispatch = dispatch[dispatch < 0].fillna(0)
              elif direction == 'absolute':
                  pass
              else:
                  return('No valid direction given.')
              dispatch = dispatch.sum()
              
          elif networkB is None:
              dispatch =\
                      network.generators_t.p[gens.index].mul(
                              network.snapshot_weightings, axis=0).sum().groupby(
                      [network.generators.bus, network.generators.carrier]).sum()
      
      fig, ax = plt.subplots(1, 1)          
      scaling = 1/(max(abs(dispatch.groupby(level=0).sum())))*scaling
      if direction != 'absolute':
          colors = coloring()
          subcolors = {a: colors[a] for a in techs}
          dispatch = dispatch.abs() + 1e-9
      else:
          dispatch = dispatch.sum(level=0)
          colors = {s[0]: 'green' if s[1] > 0 else 'red' 
                    for s in dispatch.iteritems()}
          dispatch = dispatch.abs()
          subcolors = {'negative': 'red', 'positive': 'green'}
      
      network.plot(
              bus_sizes=dispatch * scaling,
              bus_colors=colors,
              line_widths=0.2,
              margin=0.01,
              ax=ax)
  
      fig.subplots_adjust(right=0.8)
      plt.subplots_adjust(wspace=0, hspace=0.001)
  
      patchList = []
      for key in subcolors:
          data_key = mpatches.Patch(color=subcolors[key], label=key)
          patchList.append(data_key)
  
      ax.legend(handles=patchList, loc='upper left')
      ax.autoscale()
  
      if filename is None:
          plt.show()
      else:
          plt.savefig(filename)
          plt.close()
  
      return