Generate a heatmap in MatPlotLib using a scatter data set

后端 未结 12 2140
南方客
南方客 2020-11-22 09:22

I have a set of X,Y data points (about 10k) that are easy to plot as a scatter plot but that I would like to represent as a heatmap.

I looked through the examples in

12条回答
  •  旧时难觅i
    2020-11-22 10:16

    Make a 2-dimensional array that corresponds to the cells in your final image, called say heatmap_cells and instantiate it as all zeroes.

    Choose two scaling factors that define the difference between each array element in real units, for each dimension, say x_scale and y_scale. Choose these such that all your datapoints will fall within the bounds of the heatmap array.

    For each raw datapoint with x_value and y_value:

    heatmap_cells[floor(x_value/x_scale),floor(y_value/y_scale)]+=1

提交回复
热议问题