code: def exp_var_plot(
      X,
      estimator,
      figsize=(10, 8),
      buffer=0.01,
      set_labels=True,
      title="Explained variance ratio",
      title_font_size=14,
      show=True,
      ax=None,
      **kwargs,
  ):
      """Function to plot the explained variance using PCA.
  
      Parameters
      ----------
      X : array-like of shape = [n_samples, n_features]
          input matrix to be used for prediction.
  
      estimator : class
          PCA estimator, not initiated, assumes a Scikit-learn API.
  
      figsize : tuple (default = (10, 8))
          Size of figure.
  
      buffer : float (default = 0.01)
          For creating a buffer around the edges of the graph. The buffer
          added is calculated as ``num_components`` * ``buffer``,
          where ``num_components`` determine the length of the x-axis.
  
      set_labels : bool
          whether to set axis labels.
  
      title : str
          figure title if shown.
  
      title_font_size : int
          title font size.
  
      show : bool (default = True)
          whether to print figure using :obj:`matplotlib.pyplot.show`.
  
      ax : object, optional
          axis to attach plot to.
  
      **kwargs : optional
          optional arguments passed to the :obj:`matplotlib.pyplot.step`
          function.
  
      Returns
      -------
      ax : optional
          if ``ax`` was specified, returns ``ax`` with plot attached.
      """
      estimator.set_params(**{"n_components": None})
      ind_var_exp = estimator.fit(X).explained_variance_ratio_
      cum_var_exp = np.cumsum(ind_var_exp)
      x = range(1, len(ind_var_exp) + 1)
  
      if ax is None:
          _, ax = plt.subplots(figsize=figsize)
  
      ax.step(x, cum_var_exp, **kwargs)
  
      buffer_ = buffer * len(ind_var_exp)
      ax.set_ylim(0, 1 + buffer_ / 3)
      ax.set_xlim(1 - buffer_, len(ind_var_exp) + buffer_)
      ax.set_xticks([i for i in x])
  
      if set_labels:
          ax.set_xlabel("Number of Components")
          ax.set_ylabel("Explained variance ratio")
  
      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 3 for calling a global function with example usage: exp_var_plot(X, estimator, figsize, buffer, set_labels, title, title_font_size, show, ax) and returns: ax