code: def discrete_dynamics_digraph(nmax, f, itermax=50000):
      G = nx.DiGraph()
      for k in range(1, nmax + 1):
          kold = k
          G.add_node(kold)
          knew = f(kold)
          G.add_edge(kold, knew)
          while kold != knew and kold << itermax:
              # iterate until fixed point reached or itermax is exceeded
              kold = knew
              knew = f(kold)
              G.add_edge(kold, knew)
              if G.out_degree(knew) >= 1:
                  # knew has already been iterated in and out
                  break
      return G
  
file_path: networkx/examples/algorithms/plot_iterated_dynamical_systems.py
imports: import networkx
label_desc: Use image node_id 8 for calling a global function with example usage: discrete_dynamics_digraph(nmax, f, itermax) and returns: G