This seems like a simple task or a repeat, but bear with me– I’ve searched for a little while and haven’t found any easy answers.
I have a scatterplot that I would like to display as a heatmap. My values look like this:
{ (3, 3): 1.7314, (3,4):-6.99, (4,3):-17.3, (4, 4):-100.0 }
I would like to display a matrix starting with cell (3,3), which has a brightness of 1.7314, etc.
I have found several questions and answers regarding situations where you give lists of two dimensional tuples (X, Y) and the Z value (the intensity) for each point (x,y,z) is created by the number of occurrences around (x, y).
I have also used imshow to draw such a plot, but for imshow you drop the (3,3), etc. So things can be shifted strangely. One option is to use imshow and then manually adjust the axis labels afterward. But I feel like someone must have solved this before without hacking pylab too much.
What is the best way to do this?
Ok, let’s try an easy example using your sample data:
As you see, you can control the axes by specifying the limits using
extent. The default (ifNone) would be(-0.5, numcols-0.5, -0.5, numrows-0.5)(left, right, bottom, top) if you specify you want theoriginin the lower part, for the Y axis.Also,
interpolation='none'is important for your case.