def visualize_explanation(explanation, label=None):
    """
    Given the output of the explain() endpoint, produces a terminal visual that plots response strength over a sequence
    """
    if not sys.version_info[:2] >= (3, 5):
      raise IndicoError("Python >= 3.5+ is required for explanation visualization")

    try:
      from colr import Colr as C
    except ImportError:
      raise IndicoError("Package colr >= 0.8.1 is required for explanation visualization.")

    cursor = 0
    text = explanation['text']
    for token in explanation.get('token_predictions'):
        try:
            class_confidence = token.get('prediction')[label]
        except KeyError:
            raise IndicoError("Invalid label: {}".format(label))

        if class_confidence > 0.5:
            fg_color = (255, 255, 255)
        else:
            fg_color = (0, 0, 0)
        rg_value = 255 - int(class_confidence * 255)
        token_end = token.get('token').get('end')
        token_text = text[cursor:token_end]
        cursor = token_end
        sys.stdout.write(
          str(C().b_rgb(
            rg_value, rg_value, 255
          ).rgb(
            fg_color[0], fg_color[1], fg_color[2], token_text
          ))
        )
    sys.stdout.write("\n")
    sys.stdout.flush()
Given the output of the explain() endpoint, produces a terminal visual that plots response strength over a sequence