code: def plot_image_components(
      x,
      coefficients=None,
      mean=0,
      components=None,
      imshape=(8, 8),
      n_components=6,
      fontsize=12,
  ):
      if coefficients is None:
          coefficients = x
  
      if components is None:
          components = np.eye(len(coefficients), len(x))
  
      mean = np.zeros_like(x) + mean
  
      fig = plt.figure(figsize=(1.2 * (5 + n_components), 1.2 * 2))
      g = plt.GridSpec(2, 5 + n_components, hspace=0.3)
  
      def show(i, j, x, title=None):
          ax = fig.add_subplot(g[i, j], xticks=[], yticks=[])
          ax.imshow(x.reshape(imshape), interpolation="nearest")
          if title:
              ax.set_title(title, fontsize=fontsize)
  
      show(slice(2), slice(2), x, "True")
  
      approx = mean.copy()
      show(0, 2, np.zeros_like(x) + mean, r"$\mu$")
      show(1, 2, approx, r"$1 \cdot \mu$")
  
      for i in range(0, n_components):
          approx = approx + coefficients[i] * components[i]
          show(0, i + 3, components[i], r"$c_{0}$".format(i + 1))
          show(
              1,
              i + 3,
              approx,
              r"${0:.2f} \cdot c_{1}$".format(coefficients[i], i + 1),
          )
          plt.gca().text(
              0,
              1.05,
              "$+$",
              ha="right",
              va="bottom",
              transform=plt.gca().transAxes,
              fontsize=fontsize,
          )
  
      show(slice(2), slice(-2, None), approx, "Approx")
  
file_path: data-science-ipython-notebooks/scikit-learn/fig_code/figures.py
imports: import numpy
  import matplotlib.pyplot
  import warnings
label_desc: Use image node_id 6 for calling a global function with example usage: plot_image_components(x, coefficients, mean, components, imshape, n_components, fontsize) without return types