annotate_heatmap

mdtools.plot.annotate_heatmap(im, data=None, xpos=None, ypos=None, fmt='{x:.1f}', textcolors=('black', 'white'), threshold=None, **kwargs)[source]

Annotate a heatmap.

See Creating annotated heatmaps and how to annotate heatmap with text in matplotlib?

Parameters:
  • im (matplotlib.image.AxesImage or matplotlib.collections.QuadMesh) – The heatmap to be labeled.

  • data (array_like, optional) – Data to annotate. If None, the heatmap’s data is used.

  • xpos, ypos (array_like, optional) – Arrays containing the x and y positions of the annotations. If None, the text positions are tried to be inferred from data. This will only work for heatmaps whose quadrilaterals are located at integer positions.

  • fmt (str, optional) – The format of the annotations inside the heatmap. This should either use the string format method, e.g. “$ {x:.2f}”, or be a matplotlib.ticker.Formatter.

  • textcolors (array_like, optional) – A list or array of two color specifications. The first is used for data below threshold, the second for those above.

  • threshold (scalar, optional) – Value in data units according to which the colors from textcolors are applied. If None (the default) uses the middle of the colormap as separation.

  • kwargs (dict, optional) – Keyword arguments to pass to matplotlib.image.AxesImage.axes.text(). See there for possible keyword arguments.

Returns:

texts (list) – List of matplotlib.text.Text objects.