seaborn heatmap annotation ValueError: Unknown format code 'g' for object of type 'numpy.str_'
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puddle Jumping Looping
--
Chapters
00:00 Question
02:07 Accepted answer (Score 10)
02:42 Thank you
--
Full question
https://stackoverflow.com/questions/6901...
Question links:
[seaborn.heatmap]: https://seaborn.pydata.org/generated/sea...
[image]: https://i.stack.imgur.com/8uy4C.png
[these examples]: https://stackabuse.com/ultimate-guide-to.../
[seaborn.heatmap]: https://seaborn.pydata.org/generated/sea...
[seaborn.heatmap]: https://seaborn.pydata.org/generated/sea...
[seaborn.heatmap]: https://seaborn.pydata.org/generated/sea...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #numpy #matplotlib #seaborn #heatmap
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puddle Jumping Looping
--
Chapters
00:00 Question
02:07 Accepted answer (Score 10)
02:42 Thank you
--
Full question
https://stackoverflow.com/questions/6901...
Question links:
[seaborn.heatmap]: https://seaborn.pydata.org/generated/sea...
[image]: https://i.stack.imgur.com/8uy4C.png
[these examples]: https://stackabuse.com/ultimate-guide-to.../
[seaborn.heatmap]: https://seaborn.pydata.org/generated/sea...
[seaborn.heatmap]: https://seaborn.pydata.org/generated/sea...
[seaborn.heatmap]: https://seaborn.pydata.org/generated/sea...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #numpy #matplotlib #seaborn #heatmap
#avk47
ACCEPTED ANSWER
Score 15
It is a formatting issue. Here the fmt = '' is required if you are using non-numeric labels (defaults to: fmt='.2g') which consider only for numeric values and throw an error for labels with text format.
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
n1 = 5
n2 = 10
M = np.random.random((n1, n2))
A = np.array([[f'{M[i, j]:.2f}' for j in range(n2)] for i in range(n1)])
A[:, 3] = ''
fig, ax = plt.subplots(figsize = (6, 3))
sns.heatmap(ax = ax, data = M, annot = A, fmt='')
plt.show()