code: def plt_compare_timeseries(
      df_dict,
      time_col,
      value_col,
      legends_dict=None,
      colors_dict=None,
      start_time=None,
      end_time=None,
      transform=lambda x: x,
      transform_name="",
      plt_title="",
      alpha=0.6,
      linewidth=4,
  ):
      """Compare a collection by of timeseries (given in `df_dict`)
         by overlaying them in the specified period between
         ``start_time`` and ``end_time``.
  
      :param df_dict: Dict[str, pd.DataFrame]
          The keys are the arbitrary labels for each dataframe provided by the user.
          The values are dataframes each containing a timeseries
          with `time_col` and `value_col` as columns.
      :param time_col: str
          The column denoting time in datetime format.
      :param value_col: str
          The value column of interest for the y axis.
      :param legends_dict: Optional[Dict[str, str]]
          Labels for plot legend.
          The keys are the df_dict labels (or a subset of them).
          The values are the labels appearing in the plot legend.
          If not provided or None, the `df_dict` keys will be used.
      :param colors_dict: Optional[Dict[str, str]]
          A dictionary determining the color for each series in `df_dict`.
          The keys are the df_dict labels (or a subset of them).
          The values are the colors appearing for each curve in the plot.
          If not provided or None, the colors will be generated.
      :param start_time: Optional[datetime.datetime]
          The start time of the series plot.
      :param end_time: Optional[datetime.datetime]
          The end time of the series plot.
      :param transform: Optional[func]
          A function to transform the y values before plotting.
      :param transform_name: Optional[str]
          The name of the transformation for using in the title.
      :param plt_title: str
          Plot title.
      :param alpha: Optional[float]
          Transparency of the curves.
      :param linewidth: Optional[float]
          The width of the curves.
      """
      if start_time is not None:
          for label, df in df_dict.items():
              df_dict[label] = df[df[time_col] >= start_time]
  
      if end_time is not None:
          for label, df in df_dict.items():
              df_dict[label] = df[df[time_col] <= end_time]
  
      n = len(df_dict)
      labels = list(df_dict.keys())
      if colors_dict is None:
          hsv_tuples = [(x * 1.0 / n, 0.5, 0.5) for x in range(n)]
          rgb_tuples = [
              (lambda x: colorsys.hsv_to_rgb(*x))(x) for x in hsv_tuples
          ]
          colors_dict = {labels[i]: rgb_tuples[i] for i in range(n)}
  
      if legends_dict is None:
          legends_dict = {label: label for label in labels}
  
      fig, ax = plt.subplots()
      legend_patches = []
      for label in labels:
          df = df_dict[label]
          color = colors_dict[label]
          legend = legends_dict.get(label)
          # Avoids the following issue:
          # "ValueError: view limit minimum -36864.55 is less than 1 and is an invalid
          # Matplotlib date value. This often happens if you pass a non-datetime value
          # to an axis that has datetime units".
          dates = df[time_col].astype("O")
          # we add a legend for the given series if legend is not None
          # for that series
          if legend is not None:
              ax.plot(
                  dates,
                  transform(df[value_col]),
                  alpha=alpha,
                  color=color,
                  label=legend,
                  linewidth=linewidth,
              )
              patch = matplotlib.patches.Patch(
                  color=color, label=legend
              )
              legend_patches.append(patch)
          else:
              ax.plot(
                  dates,
                  transform(df[value_col]),
                  alpha=alpha,
                  color=color,
                  linewidth=linewidth,
              )
  
      legends = list(legends_dict.values())
      ax.legend(
          labels=[legend for legend in legends if legend is not None],
          handles=legend_patches,
      )
      fig.autofmt_xdate()  # rotates the dates
      ax.set_title(plt_title + " " + transform_name)
      plt.show()
  
file_path: greykite/greykite/common/viz/timeseries_plotting_mpl.py
imports: import colorsys
  import matplotlib
  import numpy
  from matplotlib import pyplot
  from pandas.plotting import register_matplotlib_converters
label_desc: Use image node_id 1 for calling a global function with example usage: plt_compare_timeseries(df_dict, time_col, value_col, legends_dict, colors_dict, start_time, end_time, transform, transform_name, plt_title, alpha, linewidth) without return types