code: def rescale(y, W, H, mi, ma):
      """Rescale the given array `y` to fit into the integer values
      between `0` and `H-1` for the values between ``mi`` and ``ma``.
      """
      y_new = []
  
      norm = ma - mi
      offset = (ma + mi) / 2
  
      for x in range(W):
          if is_valid(y[x]):
              normalized = (y[x] - offset) / norm
              if not is_valid(normalized):
                  y_new.append(None)
              else:
                  rescaled = Float(
                      (normalized * H + H / 2) * (H - 1) / H
                  ).round()
                  rescaled = int(rescaled)
                  y_new.append(rescaled)
          else:
              y_new.append(None)
      return y_new
  
file_path: sympy/sympy/plotting/textplot.py
imports: from sympy.core.numbers import Float
  from sympy.core.symbol import Dummy
  from sympy.utilities.lambdify import lambdify
  import math
label_desc: Use image node_id 2 for calling a global function with example usage: rescale(y, W, H, mi, ma) and returns: y_new