code: def _create_labels(rects, horizontal, ax, rotation):
      """find the position of the label for each value of each category
  
      right now it supports only up to the four categories
  
      ax: the axis on which the label should be applied
      rotation: the rotation list for each side
      """
      categories = _categories_level(list(rects.keys()))
      if len(categories) > 4:
          msg = (
              "maximum of 4 level supported for axes labeling... and 4"
              "is already a lot of levels, are you sure you need them all?"
          )
          raise ValueError(msg)
      labels = {}
      # keep it fixed as will be used a lot of times
      items = list(rects.items())
      vertical = not horizontal
  
      # get the axis ticks and labels locator to put the correct values!
      ax2 = ax.twinx()
      ax3 = ax.twiny()
      # this is the order of execution for horizontal disposition
      ticks_pos = [
          ax.set_xticks,
          ax.set_yticks,
          ax3.set_xticks,
          ax2.set_yticks,
      ]
      ticks_lab = [
          ax.set_xticklabels,
          ax.set_yticklabels,
          ax3.set_xticklabels,
          ax2.set_yticklabels,
      ]
      # for the vertical one, rotate it by one
      if vertical:
          ticks_pos = ticks_pos[1:] + ticks_pos[:1]
          ticks_lab = ticks_lab[1:] + ticks_lab[:1]
      # clean them
      for pos, lab in zip(ticks_pos, ticks_lab):
          pos([])
          lab([])
      # for each level, for each value in the level, take the mean of all
      # the sublevel that correspond to that partial key
      for level_idx, level in enumerate(categories):
          # this dictionary keep the labels only for this level
          level_ticks = dict()
          for value in level:
              # to which level it should refer to get the preceding
              # values of labels? it's rather a tricky question...
              # this is dependent on the side. It's a very crude management
              # but I couldn't think a more general way...
              if horizontal:
                  if level_idx == 3:
                      index_select = [-1, -1, -1]
                  else:
                      index_select = [+0, -1, -1]
              else:
                  if level_idx == 3:
                      index_select = [+0, -1, +0]
                  else:
                      index_select = [-1, -1, -1]
              # now I create the base key name and append the current value
              # It will search on all the rects to find the corresponding one
              # and use them to evaluate the mean position
              basekey = tuple(
                  categories[i][index_select[i]]
                  for i in range(level_idx)
              )
              basekey = basekey + (value,)
              subset = {
                  k: v
                  for k, v in items
                  if basekey == k[: level_idx + 1]
              }
              # now I extract the center of all the tiles and make a weighted
              # mean of all these center on the area of the tile
              # this should give me the (more or less) correct position
              # of the center of the category
  
              vals = list(subset.values())
              W = sum(w * h for (x, y, w, h) in vals)
              x_lab = sum(
                  _get_position(x, w, h, W) for (x, y, w, h) in vals
              )
              y_lab = sum(
                  _get_position(y, h, w, W) for (x, y, w, h) in vals
              )
              # now base on the ordering, select which position to keep
              # needs to be written in a more general form of 4 level are enough?
              # should give also the horizontal and vertical alignment
              side = (level_idx + vertical) % 4
              level_ticks[value] = y_lab if side % 2 else x_lab
          # now we add the labels of this level to the correct axis
  
          ticks_pos[level_idx](list(level_ticks.values()))
          ticks_lab[level_idx](
              list(level_ticks.keys()), rotation=rotation[level_idx]
          )
      return labels
  
imports: from statsmodels.compat.python import lrange, lzip
  from itertools import product
  import numpy
  from numpy import array, cumsum, iterable, r_
  from pandas import DataFrame
  from statsmodels.graphics import utils
label_desc: Use image node_id 14 for calling a global function with example usage: _create_labels(rects, horizontal, ax, rotation) and returns: labels