I’m trying to visualize a 2D NumPy array as a heatmap using Matplotlib. My array is n × n, and each element has a value between 0 and 1. I want each element (i, j) to be represented as a square in the heatmap, with its color corresponding to the value in the array.
In other words, I want a simple matplotlib heatmap where higher values are displayed with more intense colors and lower values with lighter colors.
What’s the best approach to create this kind of heatmap? Are there built-in functions in Matplotlib for this, or do I need to manually draw each square?
Example of the data:
import numpy as np
data = np.random.rand(5, 5) # 5x5 array with values between 0 and 1
How can I turn this into a visually clear heatmap?