code: def add_multi_vrects(
      fig,
      periods_df,
      grouping_col=None,
      start_time_col=START_TIME_COL,
      end_time_col=END_TIME_COL,
      y_min=None,
      y_max=None,
      annotation_text_col=None,
      annotation_position="top left",
      opacity=0.5,
      grouping_color_dict=None,
  ):
      """Adds vertical rectangle shadings to existing figure.
      Each vertical rectangle information is given in rows of data frame ``periods_df``.
      The information includes the beginning and end of vertical ranges of each rectangle as well as optional
      annotation.
      Rectangle colors can be grouped using a grouping given in ``grouping_col`` if available.
  
      Parameters
      ----------
      fig : `plotly.graph_objects.Figure`
          Existing plotly object which is going to be augmented with vertical
          rectangles and annotations.
      periods_df : `pandas.DataFrame`
          Data frame with at least ``start_time_col`` and ``end_time_col`` to denote the
          beginning and end of each vertical rectangle.
          This might also include ``grouping_col`` if the rectangle colors are to be grouped
          into same color within the group.
      grouping_col : `str` or None, default None
          The column which is used for grouping the vertical rectangle colors.
          For each group, the same color will be used for all periods in that group.
          If None, a dummy column will be added ("metric") with a single value (also "metric")
          which results in generating only one color for all rectangles.
      start_time_col : `str`, default ``START_TIME_COL``
          The column denoting the start of a period. The type can be any type
          consistent with the type of existing x axis in ``fig``.
      end_time_col : `str`, default ``END_TIME_COL``
          The column denoting the start of a period. The type can be any type
          consistent with the type of existing x axis in ``fig``.
      y_min : `float` or None, default None
          The lower limit of the rectangles.
      y_max : `float` or None, default None
          The upper limit of the rectangles.
      annotation_text_col : `str` or None, default None
          A column which includes annotation texts for each vertical rectangle.
      annotation_position : `str`, default "top left"
          The position of annotation texts with respect to the vertical rectangle.
      opacity : `float`, default 0.5
          The opacity of the colors. Note that the passed colors could have opacity
          as well, in which case this opacity will act as a relative opacity.
      grouping_color_dict : `dict` [`str`, `str`] or None, default None
          A dictionary to specify colors for each group given in ``grouping_col``.
          If there is no ``grouping_col`` passed, there will be only one color needed
          and in that case a dummy ``grouping_col`` will be created with the name "metric".
          Therefore user needs to specify ``grouping_color_dict = {"metric": desired_color}``.
  
      Returns
      -------
      result : `dict`
          - "fig": `plotly.graph_objects.Figure`
              Updated plotly object which is augmented with vertical
              rectangles and annotations.
          - "grouping_color_dict": `dict` [`str`, `str`]
              A dictionary with keys being the groups and the values being the colors.
  
      """
      # If there is no grouping column we add a grouping column with only one value ("metric")
      if grouping_col is None:
          grouping_col = "metric"
          periods_df["metric"] = "metric"
  
      if start_time_col not in periods_df.columns:
          raise ValueError(
              f"start_time_col: {start_time_col} is not found in ``periods_df`` columns: {periods_df.columns}"
          )
  
      if end_time_col not in periods_df.columns:
          raise ValueError(
              f"end_time_col: {end_time_col} is not found in ``periods_df`` columns: {periods_df.columns}"
          )
  
      if (
          grouping_col is not None
          and grouping_col not in periods_df.columns
      ):
          raise ValueError(
              f"grouping_col: {grouping_col} is passed but not found in ``periods_df`` columns: {periods_df.columns}"
          )
  
      if (
          annotation_text_col is not None
          and annotation_text_col not in periods_df.columns
      ):
          raise ValueError(
              f"annotation_text_col: {annotation_text_col} is passed but not found in ``periods_df`` columns: {periods_df.columns}"
          )
  
      groups = list(set(periods_df[grouping_col]))
      groups.sort()
  
      if grouping_color_dict is None:
          colors = get_distinct_colors(len(groups), opacity=1.0)
          grouping_color_dict = {
              groups[i]: colors[i] for i in range(len(groups))
          }
  
      for i, group in enumerate(groups):
          ind = periods_df[grouping_col] == group
          periods_df_group = periods_df.loc[ind]
  
          fillcolor = grouping_color_dict[group]
          for j, row in periods_df_group.iterrows():
              x0 = row[start_time_col]
              x1 = row[end_time_col]
  
              if annotation_text_col is not None:
                  annotation_text = row[annotation_text_col]
              else:
                  annotation_text = ""
              # Adds the vertical rectangles
              fig.add_vrect(
                  x0=x0,
                  y0=y_min,
                  x1=x1,
                  y1=y_max,
                  fillcolor=fillcolor,
                  opacity=opacity,
                  line_width=2,
                  line_color=fillcolor,
                  layer="below",
                  annotation_text=annotation_text,
                  annotation_position=annotation_position,
              )
      return {"fig": fig, "grouping_color_dict": grouping_color_dict}
  
file_path: greykite/greykite/common/viz/timeseries_annotate.py
imports: import pandas
  import plotly.graph_objects
  from greykite.common.constants import ACTUAL_COL
  from greykite.common.constants import ANOMALY_COL
  from greykite.common.constants import END_TIME_COL
  from greykite.common.constants import PREDICTED_ANOMALY_COL
  from greykite.common.constants import PREDICTED_COL
  from greykite.common.constants import START_TIME_COL
  from greykite.common.constants import TIME_COL
  from greykite.common.features.adjust_anomalous_data import label_anomalies_multi_metric
  from greykite.common.viz.colors_utils import get_distinct_colors
  from greykite.common.viz.timeseries_plotting import plot_forecast_vs_actual
label_desc: Use image node_id 5 for calling a global function with example usage: add_multi_vrects(fig, periods_df, grouping_col, start_time_col, end_time_col, y_min, y_max, annotation_text_col, annotation_position, opacity, grouping_color_dict) and returns: dict