Skip to content

Feature Request: Add annotations to heatmaps (imshow or pcolor*) #10956

Closed

Description

@raheson

I noticed that imshow or pcolor* do not have an option to add annotations to each box.
Currently, MPL creates heatmaps such as the one below:
image

However, MPL does not have the ability to add values to each grid box such as the image below:
image

This seems like a standard feature, which can enhance the readability of these heatmaps. In addition, this can be very helpful when values are 0.01 apart. It can help the user distinguish the heatmap values more efficiently. A proposed solution to turn on these values would look like plt.pcolor(data, showvalues=true).

Shouldn't this be included?

Activity

  1. ImportanceOfBeingErnest commented on Apr 4, 2018

    @ImportanceOfBeingErnest
    Member

    Labeling an imshow plot is as easy as

    data = ... # 2D numpy array
    ax.imshow(data)
    for i in range(data.shape[0]):
        for j in range(data.shape[1]):
            ax.text(j, i, "{:.2f}".format(data[i,j]), ha="center", va="center")
    

    Plus you have all the freedom to do the labeling just the way you wish instead of relying on some automatism.
    Also note that seaborn allows autolabeling of their heatmaps. The reason is that those heatmaps are categorical by design, while pcolor and imshow are general purpose image plots. And you wouldn't want to label the latest image you took with your camera that way I guess.
    So I'm a bit sceptical if this is really needed, given how easy it is to invoke manually.

  2. efiring commented on Apr 4, 2018

    @efiring
    Member

    Maybe this should be in a gallery example or addition to a tutorial.

  3. ImportanceOfBeingErnest commented on Apr 14, 2018

    @ImportanceOfBeingErnest
    Member

    There is now a heatmap example in the docs (via #11017).

  4. added this to the v2.2-doc milestone on Apr 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions