How to plot, with Python, a 2D matrix A[i,j]
like this:
i
is the x-axisj
is the y-axisA[i,j]
is a value between 0 and 100 that has to be drawn by a colour (ex: 0=blue, 100=red)
Is there a Python function for that?
(NB: I don't want a function that does the spectrogram for me, such as specgram
, because I want to compute the FFT of the signal myself; thus I only need a function that plots a matrix with colors)
imshow
function is dedicated to this task. You'll find several examples in the matplotlib gallery.imshow
butpcolormesh
is more what I was looking for : courspython.com/v3/visualisation_couleur.htmlpcolormesh
if you have a regular grid, why dont you useimshow
?pcolor
andpcolormesh
are very similar, but with performance differences. They are meant for irregular grids. You provide the corner coordinates and mpl draws a polygon between them. If you have a regular grid, with a constant resolution along the axisimshow
is a much better choice, more robust and much faster.extent
keyword is what you're probably looking for.