Search code examples
pythonmatplotlibmatrixgraphingimshow

How to plot data dependent on two variables in a discrete heatmap


I have 3 lists of data, x,y,z which I want to plot as a discrete colourmap type graph with the x and y being the coordinates of the z data point, and the z-value corresponding to a colour in the usual sense.

My data is of the form:

x = [0.4, 0.4, 0.4, 0.4, 0.4, 0.5, 0.5, 0.5, 0.5, 0.5]

y = [0.002, 0.0024, 0.0028, 0.0032, 0.0036, 0.002, 0.0024, 0.0028, 0.0032, 0.0036]

z = [1884.7, 1783.7, 2065.7, 1778.0, 2042.0, 2615.7, 2814.0, 2605.0, 1538.3, 1981.3]

I've tried using imshow/matshow by reshaping the z data into an m by n matrix, but the issue there is that the x/y axes only have values corresponding to the index of the z-matrix. Ideally I'd like something like the image below, but with the numbers on the axes referring to my x/y data.

Thanks very much.

enter image description here


Solution

  • You could use seaborn instead of matplotlib for a heatmap. See the following question for a nice example: Three variables as heatmap