code: def fig_legend(
      fig, n_cols, names, colors=None, styles=None, markers=None
  ):
      """Adds legend to figure and tweaks layout (call after fig is done)."""
      n, c, s, m = len(names), colors, styles, markers
      c = c if c else get_color()[:n]
      s = [""] * n if s is None else [s] * n if type(s) == str else s
      m = ["o"] * n if m is None else [m] * n if type(m) == str else m
      n_cols = int(np.ceil(n / np.ceil(n / n_cols)))
      hs = [
          lines.Line2D([0], [0], color=c, ls=s, marker=m)
          for c, s, m in zip(c, s, m)
      ]
      fig.legend(
          hs,
          names,
          bbox_to_anchor=(0.5, 1.0),
          loc="lower center",
          ncol=n_cols,
      )
      fig.tight_layout(pad=0.3, h_pad=1.08, w_pad=1.08)
  
file_path: pycls/pycls/sweep/plotting.py
imports: import matplotlib.lines
  import matplotlib.pyplot
  import matplotlib.ticker
  import numpy
  import pycls.models.regnet
  from pycls.sweep.analysis import get_info, get_vals, sort_sweep
label_desc: Use image node_id 6 for calling a global function with example usage: fig_legend(fig, n_cols, names, colors, styles, markers) without return types