code: def pca_plot(
      X,
      estimator,
      y=None,
      cmap=None,
      figsize=(10, 8),
      title="Principal Components Analysis",
      title_font_size=14,
      show=True,
      ax=None,
      **kwargs,
  ):
      """Function to plot a PCA analysis of 1, 2, or 3 dims.
  
      Parameters
      ----------
      X : array-like of shape = [n_samples, n_features]
          matrix to perform PCA analysis on.
  
      estimator : instance
          PCA estimator. Assumes a Scikit-learn API.
  
      y : array-like of shape = [n_samples, ] or None (default = None)
          training labels to be used for color highlighting.
  
      cmap : object, optional
          cmap object to pass to :obj:`matplotlib.pyplot.scatter`.
  
      figsize : tuple (default = (10, 8))
          Size of figure.
  
      title : str
          figure title if shown.
  
      title_font_size : int
          title font size.
  
      show : bool (default = True)
          whether to print figure :obj:`matplotlib.pyplot.show`.
  
      ax : object, optional
          axis to attach plot to.
  
      **kwargs : optional
          arguments to pass to :obj:`matplotlib.pyplot.scatter`.
  
      Returns
      -------
      ax : optional
          if ``ax`` was specified, returns ``ax`` with plot attached.
      """
      Z = X.values if isinstance(X, (DataFrame, Series)) else X
  
      Z = estimator.fit_transform(Z)
  
      # prep figure if no axis supplied
      if ax is None:
          f, ax = plt.subplots(figsize=figsize)
          if estimator.n_components == 3:
              ax = f.add_subplot(111, projection="3d")
  
      if cmap is None:
          cmap = ListedColormap(color_palette("husl"))
  
      if estimator.n_components == 1:
          ax.scatter(Z, c=y, cmap=cmap, **kwargs)
      elif estimator.n_components == 2:
          ax.scatter(Z[:, 0], Z[:, 1], c=y, cmap=cmap, **kwargs)
      elif estimator.n_components == 3:
          ax.scatter(
              Z[:, 0], Z[:, 1], Z[:, 2], c=y, cmap=cmap, **kwargs
          )
      else:
          raise ValueError(
              "'n_components' is too large to visualize. "
              "Set to one of [1, 2, 3]."
          )
  
      if show:
          plt.title(title, fontsize=title_font_size)
          plt.show()
  
      return ax
  
imports: from __future__ import division, print_function
  import numpy
  import warnings
label_desc: Use image node_id 2 for calling a global function with example usage: pca_plot(X, estimator, y, cmap, figsize, title, title_font_size, show, ax) and returns: ax