code: def plot_modulation_factor(
      n_samples, dim, n_expectation=1000, n_theta=20
  ):
      """Plot the modulation factor curve w.r.t. the dispersion.
  
      Plot the curve of modulation factor on the convergence of the
      empirical Fréchet mean as a function of the radius of the bubble
      distribution and for n_samples points on the sphere S_dim
      embedded in R^{dim+1}.
  
      Parameters
      ----------
      n_samples : int
          Number of samples to draw
      dim : int
          Dimension of the sphere (embedded in R^{dim+1}).
      n_expectation: int, optional (defaults to 1000)
          Number of computations for approximating the expectation.
      n_theta: int, optional (defaults to 20)
          Number of sampled radii for the bubble distribution.
  
      Returns
      -------
      matplolib figure
      """
      theta = gs.linspace(0.000001, gs.pi / 2.0 - 0.000001, n_theta)
      measured_modulation_factor = []
      error = []
      small_var_modulation_factor = []
      asymptotic_modulation_factor = []
      for theta_i in theta:
          (var, std_var) = modulation_factor(
              n_samples, theta_i, dim, n_expectation=n_expectation
          )
          measured_modulation_factor.append(var)
          error.append(std_var)
          logging.info("%d %f %f %f", n_samples, theta_i, var, std_var)
          small_var_modulation_factor.append(
              1.0
              + 2.0
              / 3.0
              * theta_i**2
              * (1.0 - 1.0 / dim)
              * (1.0 - 1.0 / n_samples)
          )
          asymptotic_modulation_factor.append(
              asymptotic_modulation(dim, theta_i)
          )
      plt.figure()
      plt.errorbar(
          theta,
          measured_modulation_factor,
          yerr=error,
          color="r",
          label="Measured",
      )
      plt.plot(
          theta,
          small_var_modulation_factor,
          "g",
          label="Small variance prediction",
      )
      plt.plot(
          theta,
          asymptotic_modulation_factor,
          "grey",
          label="Asymptotic prediction",
      )
      plt.xlabel(r"Standard deviation $\theta$")
      plt.ylabel(r"Modulation factor $\alpha$")
      plt.title(
          f"Convergence rate modulation factor, sphere dim={n_samples}, n={dim}"
      )
      plt.legend(loc="best")
      plt.draw()
  
file_path: geomstats/examples/empirical_frechet_mean_uncertainty_sn.py
imports: import logging
  import matplotlib.pyplot
  import geomstats.backend
  from geomstats.geometry.hypersphere import Hypersphere
  from geomstats.learning.frechet_mean import FrechetMean
label_desc: Use image node_id 4 for calling a global function with example usage: plot_modulation_factor(n_samples, dim, n_expectation, n_theta) without return types