code: def draw_g(graph):
      g = graph.g.to_networkx()
      fig = plt.figure(figsize=(8, 4), dpi=150)
      ax = fig.subplots()
      ax.axis("off")
      ax.set_ylim(-1, 1.5)
      en_indx = graph.nids["enc"].tolist()
      de_indx = graph.nids["dec"].tolist()
      en_l = {i: np.array([i, 0]) for i in en_indx}
      de_l = {i: np.array([i + 2, 1]) for i in de_indx}
      en_de_s = []
      for i in en_indx:
          for j in de_indx:
              en_de_s.append((i, j))
              g.add_edge(i, j)
      en_s = []
      for i in en_indx:
          for j in en_indx:
              g.add_edge(i, j)
              en_s.append((i, j))
  
      de_s = []
      for idx, i in enumerate(de_indx):
          for j in de_indx[idx:]:
              g.add_edge(i, j)
              de_s.append((i, j))
  
      nx.draw_networkx_nodes(
          g, en_l, nodelist=en_indx, node_color="r", node_size=60, ax=ax
      )
      nx.draw_networkx_nodes(
          g, de_l, nodelist=de_indx, node_color="r", node_size=60, ax=ax
      )
      draw_networkx_edges(
          g,
          en_l,
          edgelist=en_s,
          ax=ax,
          connectionstyle="arc3,rad=-0.3",
          width=0.5,
      )
      draw_networkx_edges(
          g,
          de_l,
          edgelist=de_s,
          ax=ax,
          connectionstyle="arc3,rad=-0.3",
          width=0.5,
      )
      draw_networkx_edges(
          g, {**en_l, **de_l}, edgelist=en_de_s, width=0.3, ax=ax
      )
      # ax.add_patch()
      ax.text(
          len(en_indx) + 0.5,
          0,
          "Encoder",
          verticalalignment="center",
          horizontalalignment="left",
      )
  
      ax.text(
          len(en_indx) + 0.5,
          1,
          "Decoder",
          verticalalignment="center",
          horizontalalignment="right",
      )
      delta = 0.03
      for value in {**en_l, **de_l}.values():
          x, y = value
          ax.add_patch(
              FancyArrowPatch(
                  (x - delta, y + delta),
                  (x - delta, y - delta),
                  arrowstyle="->",
                  mutation_scale=8,
                  connectionstyle="arc3,rad=3",
              )
          )
      plt.show(fig)
  
file_path: dgl/examples/pytorch/transformer/modules/viz.py
imports: import os
  import matplotlib
  import matplotlib.animation
  import matplotlib.pyplot
  import networkx
  import numpy
  import torch
  from networkx.algorithms import bipartite
  import networkx
  from matplotlib.patches import ConnectionStyle, FancyArrowPatch
  from networkx.utils import is_string_like
label_desc: Use image node_id 7 for calling a global function with example usage: draw_g(graph) without return types