code: def rankings(
      experiments, with_evc_tree=True, order_by="suggested", **kwargs
  ):
      """Plotly implementation of `orion.plotting.rankings`"""
  
      def reformat_competitions(experiments):
          if isinstance(experiments, dict) and isinstance(
              next(iter(experiments.values())), Iterable
          ):
              competitions = []
              remaining = True
              n_competitions = len(next(iter(experiments.values())))
              for ith_competition in range(n_competitions):
                  competition = {}
                  for name in experiments.keys():
                      competition[name] = experiments[name][
                          ith_competition
                      ]
                  competitions.append(competition)
          elif isinstance(experiments, dict):
              competitions = experiments
          elif isinstance(experiments, Iterable) and not isinstance(
              experiments[0], dict
          ):
              competitions = {
                  f"{experiment.name}-v{experiment.version}": experiment
                  for experiment in experiments
              }
          else:
              competitions = experiments
  
          return competitions
  
      def build_groups(competitions):
          if not isinstance(competitions, dict):
              rankings = []
              for competition in competitions:
                  rankings.append(build_frame(competition))
              df = pd.concat(rankings)
              data_frames = orion.analysis.average(
                  df,
                  group_by=["order", "name"],
                  key="rank",
                  return_var=True,
              )
          else:
              data_frames = build_frame(competitions)
  
          return data_frames
  
      def build_frame(competition):
          """Builds the dataframe for the plot"""
  
          frames = []
          for name, experiment in competition.items():
              df = experiment.to_pandas(with_evc_tree=with_evc_tree)
              df = df.loc[df["status"] == "completed"]
              df = df.sort_values(order_by)
              df = orion.analysis.regret(df)
              df["name"] = [name] * len(df)
              df["order"] = range(len(df))
              frames.append(df)
  
          df = pd.concat(frames)
  
          return orion.analysis.ranking(df)
  
      def get_objective_name(competition):
          """Infer name of objective based on trials of one experiment"""
          if not isinstance(competition, dict):
              return get_objective_name(competition[0])
  
          for experiment in competition.values():
              trials = experiment.fetch_trials_by_status("completed")
              if trials:
                  return trials[0].objective.name
          return "objective"
  
      ORDER_KEYS = ["suggested", "reserved", "completed"]
  
      if not experiments:
          raise ValueError("Parameter 'experiment' is None")
  
      if order_by not in ORDER_KEYS:
          raise ValueError(
              f"Parameter 'order_by' is not one of {ORDER_KEYS}"
          )
  
      competitions = reformat_competitions(experiments)
      df = build_groups(competitions)
  
      fig = go.Figure()
  
      if df.empty:
          return fig
  
      names = set(df["name"])
      for i, name in enumerate(sorted(names)):
          exp_data = df[df["name"] == name]
          if "rank_mean" in exp_data:
              y = exp_data["rank_mean"]
          else:
              y = exp_data["rank"]
          x = list(range(len(y)))
          fig.add_scatter(
              x=x,
              y=y,
              mode="lines",
              line=dict(color=px.colors.qualitative.G10[i]),
              name=name,
          )
          if "rank_var" in exp_data:
              dy = exp_data["rank_var"]
              fig.add_scatter(
                  x=list(x) + list(x)[::-1],
                  y=list(y - dy) + list(y + dy)[::-1],
                  fill="toself",
                  showlegend=False,
                  line=dict(
                      color=px.colors.qualitative.G10[i], width=0
                  ),
                  name=name,
              )
  
      objective = get_objective_name(competitions)
      fig.update_layout(
          title="Average Rankings",
          xaxis_title=f"Trials ordered by {order_by} time",
          yaxis_title=f"Ranking based on {objective}",
          hovermode="x",
      )
      return fig
  
imports: import functools
  from collections.abc import Iterable
  import numpy
  import pandas
  import plotly.express
  import plotly.graph_objects
  from plotly.subplots import make_subplots
  import orion.analysis
  import orion.analysis.base
  from orion.algo.space import Categorical, Fidelity
  from orion.core.worker.transformer import build_required_space
label_desc: Use image node_id 3 for calling a global function with example usage: rankings(experiments, with_evc_tree, order_by) and returns: fig, competitions, data_frames, orion, str, fig, get_objective_name, trials