Search notes:

Python matplotlib example: Heat map

This example creates a heat map with matplotlib.
import matplotlib.pyplot  as plt
import numpy              as np
from   scipy.ndimage import gaussian_filter

width  = 15
height = 10

np.random.seed(12345)

values = np.random.rand(width, height)
values = gaussian_filter(values, sigma=1.4)

plt.figure(figsize=(width, height))
plt.imshow(values, cmap = 'coolwarm')

for  x in range(width ):
 for y in range(height):
    
     plt.text(y, x, f'{x:>2},{y:>2}'           , ha = 'center', va = 'bottom', color='gray' )
     plt.text(y, x, round(values[x,y].item(),2), ha = 'center', va = 'top'   , color='black')

plt.axis('off')
# plt.show()
plt.savefig('img/heat-map.png')
Github repository about-python, path: /libraries/matplotlib/_examples/heat-map.py

See also

Heat map of Switzerland

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758631984, '216.73.216.19', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/libraries/matplotlib/_examples/heat-map(67): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78