code: def plot_lifetimes(
      durations,
      event_observed=None,
      entry=None,
      left_truncated=False,
      sort_by_duration=True,
      event_observed_color="#A60628",
      event_censored_color="#348ABD",
      ax=None,
      **kwargs,
  ):
      """
      Returns a lifetime plot, see examples: https://lifelines.readthedocs.io/en/latest/Survival%20Analysis%20intro.html#Censoring
  
      Parameters
      -----------
      durations: (n,) numpy array or pd.Series
        duration (relative to subject's birth) the subject was alive for.
      event_observed: (n,) numpy array or pd.Series
        array of booleans: True if event observed, else False.
      entry: (n,) numpy array or pd.Series
        offsetting the births away from t=0. This could be from left-truncation, or delayed entry into study.
      left_truncated: boolean
        if entry is provided, and the data is left-truncated, this will display additional information in the plot to reflect this.
      sort_by_duration: boolean
        sort by the duration vector
      event_observed_color: str
        default: "#A60628"
      event_censored_color: str
        default: "#348ABD"
  
      Returns
      -------
      ax:
  
      Examples
      ---------
      .. code:: python
  
          from lifelines.datasets import load_waltons
          from lifelines.plotting import plot_lifetimes
          T, E = load_waltons()["T"], load_waltons()["E"]
          ax = plot_lifetimes(T.loc[:50], event_observed=E.loc[:50])
  
      """
      from matplotlib import pyplot as plt
  
      if ax is None:
          ax = plt.gca()
      # If durations is pd.Series with non-default index, then use index values as y-axis labels.
      label_plot_bars = (
          type(durations) is pd.Series
          and type(durations.index) is not pd.RangeIndex
      )
  
      N = durations.shape[0]
      if N > 25:
          warnings.warn(
              "For less visual clutter, you may want to subsample to less than 25 individuals."
          )
      if event_observed is None:
          event_observed = np.ones(N, dtype=bool)
      if entry is None:
          entry = np.zeros(N)
      assert durations.shape[0] == N
      assert event_observed.shape[0] == N
  
      if sort_by_duration:
          # order by length of lifetimes;
          ix = np.argsort(entry + durations, 0)
          durations = _iloc(durations, ix)
          event_observed = _iloc(event_observed, ix)
          entry = _iloc(entry, ix)
      for i in range(N):
          c = (
              event_observed_color
              if _iloc(event_observed, i)
              else event_censored_color
          )
          ax.hlines(
              i, _iloc(entry, i), _iloc(durations, i), color=c, lw=1.5
          )
          if left_truncated:
              ax.hlines(
                  i, 0, _iloc(entry, i), color=c, lw=1.0, linestyle="--"
              )
          m = "" if not _iloc(event_observed, i) else "o"
          ax.scatter(_iloc(durations, i), i, color=c, marker=m, s=13)
      if label_plot_bars:
          ax.set_yticks(range(0, N))
          ax.set_yticklabels(durations.index)
      else:
          from matplotlib.ticker import MaxNLocator
  
          ax.yaxis.set_major_locator(MaxNLocator(integer=True))
      ax.set_xlim(0)
      ax.set_ylim(-0.5, N)
      return ax
  
imports: import warnings
  from typing import Union, Optional, Iterable
  from scipy import stats
  import pandas
  import numpy
  from lifelines.utils import coalesce, CensoringType, _group_event_table_by_intervals
label_desc: Use image node_id 13 for calling a global function with example usage: plot_lifetimes(durations, event_observed, entry, left_truncated, sort_by_duration, event_observed_color, event_censored_color, ax) and returns: ax