code: def _plot_anomaly(
      anomaly,
      axes,
      df,
      curve2axes,
      anomaly_tag,
      anomaly_color,
      anomaly_marker,
      anomaly_markersize,
      anomaly_alpha,
      match_curve_name,
      freq_as_period,
      color_generator,
      anomaly_name=None,
      anomaly_label=None,
  ):
      if isinstance(anomaly, (list, pd.Series)):
          anomaly_color = color_generator.emit(anomaly_color)
          if anomaly_tag == "span":
              # turn anomaly into list, if not yet
              if isinstance(anomaly, pd.Series):
                  anomaly = to_events(
                      anomaly, freq_as_period=freq_as_period
                  )
              anomaly = validate_events(anomaly, point_as_interval=True)
              if match_curve_name and (
                  anomaly_name in set(df.columns)
              ):  # match found, plot on it
                  for axes_ind in curve2axes[anomaly_name]:
                      _add_anomaly_list_to_axes(
                          anomaly,
                          axes[axes_ind],
                          anomaly_color,
                          anomaly_alpha,
                          (
                              anomaly_label
                              if (anomaly_label != anomaly_name)
                              else "Anomaly - {}".format(anomaly_name)
                          ),
                      )
              else:  # not match found or don't match, plot on all
                  for ax in axes:
                      _add_anomaly_list_to_axes(
                          anomaly,
                          ax,
                          anomaly_color,
                          anomaly_alpha,
                          (
                              "Anomaly - {}".format(anomaly_name)
                              if (
                                  (anomaly_label == anomaly_name)
                                  and (anomaly_name in set(df.columns))
                              )
                              else anomaly_label
                          ),
                      )
          elif anomaly_tag == "marker":
              # turn anomaly into binary series, if not yet
              if isinstance(anomaly, list):
                  anomaly = to_labels(
                      anomaly, df.index, freq_as_period=freq_as_period
                  )
              else:
                  try:
                      pd.testing.assert_index_equal(
                          anomaly.index, df.index, check_names=False
                      )
                  except AssertionError:
                      raise ValueError(
                          "Series index in argument `anomaly` must be the same "
                          "as the input time series."
                      )
              if match_curve_name and (
                  anomaly_name in set(df.columns)
              ):  # match found, plot on it
                  for axes_ind in curve2axes[anomaly_name]:
                      _add_anomaly_series_to_curve(
                          anomaly,
                          axes[axes_ind],
                          df[anomaly_name],
                          anomaly_color,
                          anomaly_marker,
                          anomaly_markersize,
                          (
                              anomaly_label
                              if (anomaly_label != anomaly_name)
                              else "Anomaly - {}".format(anomaly_name)
                          ),
                      )
              else:  # not match found or don't match, plot on all
                  # hasLegend is an auxilary variable to make sure an anomaly
                  # series only appears once in legend in an axes
                  hasLegend = [False] * len(axes)
                  for curve, axes_inds in curve2axes.items():
                      for axes_ind in axes_inds:
                          _add_anomaly_series_to_curve(
                              anomaly,
                              axes[axes_ind],
                              df[curve],
                              anomaly_color,
                              anomaly_marker,
                              anomaly_markersize,
                              (
                                  "Anomaly - {}".format(anomaly_name)
                                  if (
                                      (anomaly_label == anomaly_name)
                                      and (
                                          anomaly_name
                                          in set(df.columns)
                                      )
                                  )
                                  else anomaly_label
                              )
                              if not hasLegend[axes_ind]
                              else None,
                          )
                          hasLegend[axes_ind] = True
          else:
              raise ValueError(
                  "An anomaly tag must be either 'span' or 'marker'."
              )
      elif isinstance(anomaly, (pd.DataFrame, dict)):
          for key in (
              anomaly.columns
              if isinstance(anomaly, pd.DataFrame)
              else anomaly.keys()
          ):
              _plot_anomaly(
                  anomaly[key],
                  axes,
                  df,
                  curve2axes,
                  anomaly_tag[key],
                  anomaly_color[key],
                  anomaly_marker[key],
                  anomaly_markersize[key],
                  anomaly_alpha[key],
                  match_curve_name,
                  freq_as_period,
                  color_generator,
                  anomaly_name=key,
                  anomaly_label=(
                      "{} - {}".format(anomaly_name, key)
                      if (anomaly_name is not None)
                      else key
                  ),
              )
      else:
          raise TypeError(
              "Argument `anomaly` must be a list, pandas Series, DataFrame, or "
              "a (nested) dict of them."
          )
  
file_path: adtk/src/adtk/visualization/_visualization.py
imports: import matplotlib.pyplot
  import numpy
  import pandas
  from pandas.plotting import register_matplotlib_converters
  from ..data import to_events, to_labels, validate_events
label_desc: Use image node_id 4 for calling a global function with example usage: _plot_anomaly(anomaly, axes, df, curve2axes, anomaly_tag, anomaly_color, anomaly_marker, anomaly_markersize, anomaly_alpha, match_curve_name, freq_as_period, color_generator, anomaly_name, anomaly_label) without return types