code: def repel_text(
      texts,
      renderer=None,
      ax=None,
      expand=(1.2, 1.2),
      only_use_max_min=False,
      move=False,
  ):
      """
      Repel texts from each other while expanding their bounding boxes by expand
      (x, y), e.g. (1.2, 1.2) would multiply width and height by 1.2.
      Requires a renderer to get the actual sizes of the text, and to that end
      either one needs to be directly provided, or the axes have to be specified,
      and the renderer is then got from the axes object.
      """
      if ax is None:
          ax = plt.gca()
      if renderer is None:
          r = get_renderer(ax.get_figure())
      else:
          r = renderer
      bboxes = get_bboxes(texts, r, expand, ax=ax)
      xmins = [bbox.xmin for bbox in bboxes]
      xmaxs = [bbox.xmax for bbox in bboxes]
      ymaxs = [bbox.ymax for bbox in bboxes]
      ymins = [bbox.ymin for bbox in bboxes]
  
      overlaps_x = np.zeros((len(bboxes), len(bboxes)))
      overlaps_y = np.zeros_like(overlaps_x)
      overlap_directions_x = np.zeros_like(overlaps_x)
      overlap_directions_y = np.zeros_like(overlaps_y)
      for i, bbox1 in enumerate(bboxes):
          overlaps = get_points_inside_bbox(
              xmins * 2 + xmaxs * 2, (ymins + ymaxs) * 2, bbox1
          ) % len(bboxes)
          overlaps = np.unique(overlaps)
          for j in overlaps:
              bbox2 = bboxes[j]
              x, y = bbox1.intersection(bbox1, bbox2).size
              overlaps_x[i, j] = x
              overlaps_y[i, j] = y
              direction = np.sign(bbox1.extents - bbox2.extents)[:2]
              overlap_directions_x[i, j] = direction[0]
              overlap_directions_y[i, j] = direction[1]
  
      move_x = overlaps_x * overlap_directions_x
      move_y = overlaps_y * overlap_directions_y
  
      delta_x = move_x.sum(axis=1)
      delta_y = move_y.sum(axis=1)
  
      q = np.sum(overlaps_x), np.sum(overlaps_y)
      if move:
          move_texts(texts, delta_x, delta_y, bboxes, ax=ax)
      return delta_x, delta_y, q
  
imports: from __future__ import division
  import sys
  from itertools import product
  from operator import itemgetter
  import matplotlib
  import numpy
  from matplotlib import pyplot
  from matplotlib.path import get_path_collection_extents
label_desc: Use image node_id 10 for calling a global function with example usage: repel_text(texts, renderer, ax, expand, only_use_max_min, move) and returns: delta_x,  delta_y,  q