code: def plot_multivariate_grouped(
      df,
      x_col,
      y_col_style_dict,
      grouping_x_col,
      grouping_x_col_values,
      grouping_y_col_style_dict,
      colors=DEFAULT_PLOTLY_COLORS,
      xlabel=None,
      ylabel=cst.VALUE_COL,
      title=None,
      showlegend=True,
  ):
      """Plots multiple lines against the same x-axis values. The lines can
      partially share the x-axis values.
  
      See parameter descriptions for a running example.
  
      Parameters
      ----------
      df : `pandas.DataFrame`
          Data frame with ``x_col`` and columns named by the keys in ``y_col_style_dict``,
          ``grouping_x_col``, ``grouping_y_col_style_dict``.
  
          For example::
  
              df = pd.DataFrame({
                  time: [dt(2018, 1, 1),
                          dt(2018, 1, 2),
                          dt(2018, 1, 3)],
                  "y1": [8.5, 2.0, 3.0],
                  "y2": [1.4, 2.1, 3.4],
                  "y3": [4.2, 3.1, 3.0],
                  "y4": [0, 1, 2],
                  "y5": [10, 9, 8],
                  "group": [1, 2, 1],
              })
          This will be our running example.
      x_col: `str`
          Which column to plot on the x-axis.
          "time" in our example.
      y_col_style_dict: `dict` [`str`, `dict` or None]
          The column(s) to plot on the y-axis, and how to style them.
          These columns are plotted against the complete x-axis.
  
          - key : `str`
              column name in ``df``
          - value : `dict` or None
              Optional styling options, passed as kwargs to `go.Scatter`.
              If None, uses the default: line labeled by the column name.
              If line color is not given, it is added according to ``colors``.
              See reference page for `plotly.graph_objects.Scatter` for options
              (e.g. color, mode, width/size, opacity).
              https://plotly.com/python/reference/#scatter.
  
          For example::
  
              y_col_style_dict={
                  "y1": {
                      "name": "y1_name",
                      "legendgroup": "one",
                      "mode": "markers",
                      "line": None  # Remove line params since we use mode="markers"
                  },
                  "y2": None,
              }
  
          The function will add a line color to "y1" and "y2" based on the ``colors`` parameter.
          It will also add a name to "y2", since none was given. The "name" of "y1" will be preserved.
  
          The output ``fig`` will have one line each for each of "y1" and "y2", each plot against
          the entire "time" column.
      grouping_x_col: `str`
          Which column to use to group columns in ``grouping_y_col_style_dict``.
          "group" in our example.
      grouping_x_col_values: `list` [`int`] or None
          Which values to use for grouping. If None, uses all the unique values in
          ``df`` [``grouping_x_col``].
          In our example, specifying ``grouping_x_col_values == [1, 2]`` would plot
          separate lines corresponding to ``group==1`` and ``group==2``.
      grouping_y_col_style_dict: `dict` [`str`, `dict` or None]
          The column(s) to plot on the y-axis, and how to style them.
          These columns are plotted against partial x-axis.
          For each ``grouping_x_col_values`` an element in this dictionary produces
          one line.
  
          - key : `str`
              column name in ``df``
          - value : `dict` or None
              Optional styling options, passed as kwargs to `go.Scatter`.
              If None, uses the default: line labeled by the ``grouping_x_col_values``,
              ``grouping_x_col`` and column name.
              If a name is given, it is augmented with the ``grouping_x_col_values``.
              If line color is not given, it is added according to ``colors``.
              All the lines sharing same ``grouping_x_col_values`` have the same color.
              See reference page for `plotly.graph_objects.Scatter` for options
              (e.g. color, mode, width/size, opacity).
              https://plotly.com/python/reference/#scatter.
  
          For example::
  
              grouping_y_col_style_dict={
                  "y3": {
                      "line": {
                          "color": "blue"
                      }
                  },
                  "y4": {
                      "name": "y4_name",
                      "line": {
                          "width": 2,
                          "dash": "dot"
                      }
                  },
                  "y5": None,
              }
  
          The function will add a line color to "y4" and "y5" based on the ``colors`` parameter.
          The line color of "y3" will be "blue" as specified. We also preserve the given line
          properties of "y4".
  
      `   The function adds a name to "y3" and "y5", since none was given. The given "name" of "y4"
          will be augmented with ``grouping_x_col_values``.
  
          Each element of ``grouping_y_col_style_dict`` gets one line for each ``grouping_x_col_values``.
          In our example, there will be 2 lines corresponding to "y3", named "1_y3" and "2_y3".
          "1_y3" is plotted against "time = [dt(2018, 1, 1), dt(2018, 1, 3)]", corresponding to ``group==1``.
          "2_y3" is plotted against "time = [dt(2018, 1, 2)", corresponding to ``group==2``.
      colors: [`str`, `list` [`str`]], default ``DEFAULT_PLOTLY_COLORS``
          Which colors to use to build a color palette for plotting.
          This can be a list of RGB colors or a `str` from ``PLOTLY_SCALES``.
          Required number of colors equals sum of the length of ``y_col_style_dict``
          and length of ``grouping_x_col_values``.
          See `~greykite.common.viz.colors_utils.get_color_palette` for details.
      xlabel : `str` or None, default None
          x-axis label. If None, default is ``x_col``.
      ylabel : `str` or None, default ``VALUE_COL``
          y-axis label
      title : `str` or None, default None
          Plot title. If None, default is based on axis labels.
      showlegend : `bool`, default True
          Whether to show the legend.
  
      Returns
      -------
      fig : `plotly.graph_objects.Figure`
      Interactive plotly graph of one or more columns
      in ``df`` against ``x_col``.
  
      See `~greykite.common.viz.timeseries_plotting.plot_forecast_vs_actual`
      return value for how to plot the figure and add customization.
      """
  
      available_grouping_x_col_values = np.unique(df[grouping_x_col])
      if grouping_x_col_values is None:
          grouping_x_col_values = available_grouping_x_col_values
      else:
          missing_grouping_x_col_values = set(
              grouping_x_col_values
          ) - set(available_grouping_x_col_values)
          if len(missing_grouping_x_col_values) > 0:
              raise ValueError(
                  f"Following 'grouping_x_col_values' are missing in '{grouping_x_col}' column: "
                  f"{missing_grouping_x_col_values}"
              )
  
      # Chooses the color palette
      n_color = len(y_col_style_dict) + len(grouping_x_col_values)
      color_palette = get_color_palette(num=n_color, colors=colors)
  
      # Updates colors for y_col_style_dict if it is not specified
      for color_num, (column, style_dict) in enumerate(
          y_col_style_dict.items()
      ):
          if style_dict is None:
              style_dict = {}
          default_color = {"color": color_palette[color_num]}
          style_dict["line"] = update_dictionary(
              default_color, overwrite_dict=style_dict.get("line")
          )
          y_col_style_dict[column] = style_dict
  
      # Standardizes dataset for the next figure
      df_standardized = (
          df.copy()
          .drop_duplicates(subset=[x_col])
          .sort_values(by=x_col)
      )
  
      # This figure plots the whole xaxis vs yaxis values
      fig = plot_multivariate(
          df=df_standardized,
          x_col=x_col,
          y_col_style_dict=y_col_style_dict,
          xlabel=xlabel,
          ylabel=ylabel,
          title=title,
          showlegend=showlegend,
      )
      data = fig.data
      layout = fig.layout
  
      # These figures plot the sliced xaxis vs yaxis values
      for color_num, grouping_x_col_value in enumerate(
          grouping_x_col_values, len(y_col_style_dict)
      ):
          default_color = {"color": color_palette[color_num]}
  
          sliced_y_col_style_dict = grouping_y_col_style_dict.copy()
  
          for column, style_dict in sliced_y_col_style_dict.items():
              # Updates colors if it is not specified
              if style_dict is None:
                  style_dict = {}
              line_dict = update_dictionary(
                  default_color, overwrite_dict=style_dict.get("line")
              )
  
              # Augments names with grouping_x_col_value
              name = style_dict.get("name")
              if name is None:
                  updated_name = f"{grouping_x_col_value}_{grouping_x_col}_{column}"
              else:
                  updated_name = f"{grouping_x_col_value}_{name}"
  
              overwrite_dict = {"name": updated_name, "line": line_dict}
              style_dict = update_dictionary(
                  style_dict, overwrite_dict=overwrite_dict
              )
              sliced_y_col_style_dict[column] = style_dict
  
          df_sliced = df[df[grouping_x_col] == grouping_x_col_value]
          fig = plot_multivariate(
              df=df_sliced,
              x_col=x_col,
              y_col_style_dict=sliced_y_col_style_dict,
          )
          data = data + fig.data
  
      fig = go.Figure(data=data, layout=layout)
  
      return fig
  
imports: import warnings
  import numpy
  import pandas
  import plotly.graph_objects
  from plotly.colors import DEFAULT_PLOTLY_COLORS
  from plotly.subplots import make_subplots
  from greykite.common import constants
  from greykite.common.features.timeseries_features import build_time_features_df
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.python_utils import update_dictionary
  from greykite.common.viz.colors_utils import get_color_palette
  from greykite.common.viz.colors_utils import get_distinct_colors
label_desc: Use image node_id 2 for calling a global function with example usage: plot_multivariate_grouped(df, x_col, y_col_style_dict, grouping_x_col, grouping_x_col_values, grouping_y_col_style_dict, colors, xlabel, ylabel, title, showlegend) and returns: fig