Only the first row of annotations displayed on seaborn heatmap
Asked Answered
M

6

38

As it's usually advised, I have managed to reduce my problem to a minimal reproducible example:

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

matrix = np.array([[0.1234, 1.4567, 0.7890, 0.1234],
                   [0.9876, 0, 0.5432, 0.6789],
                   [0.1111, 0.2222, 0, 0.3333],
                   [0.4444, 0.5555, 0.6666, 0]])
sns.heatmap(matrix, annot=True)
plt.show()

Vaguely based on Seaborn official documentation.

Unfortunately, unlike what would be expected (all numbers visible), I get only the numbers in the top row visible:

enter image description here


As there is not really much room for error in this one, I'm out of ideas and google/SO doesn't seem to have this question asked before. Is this a bug?


I am running:

Seaborn 0.12.2
Matplotlib 3.8.0
PyCharm 2023.1.4
Windows 10
Mercantilism answered 23/9, 2023 at 22:19 Comment(6)
Using seaborn version 0.12.2 the plot has all the annotations. What version are you on?Scandian
I ran and got the excepted output on the 0.12.2 versionBel
Updated the post with my environmentSazerac
My environment (on Windows 10) is running Matplotlib 3.7.1. The PyCharm version shouldn't affect the results. Maybe it's a bug related to a new version of Matplotlib?Scandian
This is a result of a change in matplotlib: github.com/mwaskom/seaborn/issues/3478Achorn
To summarize: there was a change in Matplotlib 3.8 that is causing this issue. It will be fixed in a future version, but for now, the fix is to downgrade to Matplotlib 3.7 to get the desired results.Scandian
S
32

Just ran into the issue myself, I was on Seaborn 0.12.2. Ran pip install seaborn --upgrade and now have 0.13.0

Restarted vscode and annotations appeared.

Swamp answered 4/10, 2023 at 17:4 Comment(0)
M
15

Thanks to a comment by @mwaskom, it seems like it's a Matplotlib issue with a documented solution:

Looks like problem goes away if I downgrade MATPLOTLIB to version 3.7.3.

Mercantilism answered 23/9, 2023 at 23:44 Comment(0)
K
11

Yes, issue was for Seaborn 0.12.2, Seaborn 0.13.0 solves the issue.

Kirchner answered 3/10, 2023 at 0:35 Comment(0)
S
3
!pip install seaborn --upgrade

In vscode works fine for me in macbook pro m1. Relaunch after upgrade.

Solar answered 17/1 at 8:45 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Meares
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewMalley
E
0

For those on earlier versions.

I am using seaborn version 0.13.0 and it works nicely.

Escudo answered 1/10, 2023 at 15:42 Comment(0)
M
0

I was facing the same issue when i was using the matplolib version 3.8.0 however i changed my version to 3.7.3 it's working now.

Margarito answered 4/7 at 15:39 Comment(1)
Your solution has already been posted for this question, please double-check before adding an answer. Thanks.Hectograph

© 2022 - 2024 — McMap. All rights reserved.