code: def prediction_interval_plot_as_png_base64(
      df,
      time,
      signal,
      estimator,
      lower,
      upper,
      name=None,
      max_length=1000,
  ):
      assert df.shape[0] > 0
      assert df.shape[1] > 0
      assert time in df.columns
      assert signal in df.columns
      assert estimator in df.columns
      assert lower in df.columns
      assert upper in df.columns
  
      df1 = df.tail(max_length).copy()
      lMin = np.mean(df1[signal]) - np.std(df1[signal]) * 3
      lMax = np.mean(df1[signal]) + np.std(df1[signal]) * 3
      df1[lower] = df1[lower].apply(
          lambda x: x if (np.isnan(x) or x >= lMin) else np.nan
      )
      df1[upper] = df1[upper].apply(
          lambda x: x if (np.isnan(x) or x <= lMax) else np.nan
      )
  
      # last value of the signal
      lLastSignalPos = df1[signal].dropna().tail(1).index
      lEstimtorValue = df1[estimator][lLastSignalPos]
      df1.loc[lLastSignalPos, lower] = lEstimtorValue
      df1.loc[lLastSignalPos, upper] = lEstimtorValue
  
      import matplotlib
  
      # matplotlib.use('Agg')
      import matplotlib.pyplot as plt
  
      plt.switch_backend("Agg")
      fig, axs = plt.subplots(ncols=1, figsize=(16, 8))
      df1.plot.line(
          time,
          [signal, estimator, lower, upper],
          color=[
              SIGNAL_COLOR,
              FORECAST_COLOR,
              FORECAST_COLOR,
              FORECAST_COLOR,
          ],
          ax=axs,
          grid=True,
          legend=False,
      )
      add_patched_legend(axs, [signal, estimator, lower, upper])
  
      x = df1[time]
      type1 = np.dtype(x)
      if type1.kind == "M":
          x = x.apply(lambda t: t.date())
      axs.fill_between(
          x.values,
          df1[lower],
          df1[upper],
          color=SHADED_COLOR,
          alpha=0.5,
      )
  
      figfile = BytesIO()
      fig.savefig(figfile, format="png")
      plt.close(fig)
      figfile.seek(0)  # rewind to beginning of file
      figdata_png = base64.b64encode(figfile.getvalue())
      return figdata_png.decode("utf8")
  
file_path: atspy/atspy/TS/Plots.py
imports: import pandas
  import numpy
  from io import BytesIO
  import base64
label_desc: Use image node_id 5 for calling a global function with example usage: prediction_interval_plot_as_png_base64(df, time, signal, estimator, lower, upper, name, max_length) and returns: figdata_png