Generate a heatmap in MatPlotLib using a scatter data set

后端 未结 12 2242
南方客
南方客 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条回答
  •  情话喂你
    2020-11-22 10:06

    Very similar to @Piti's answer, but using 1 call instead of 2 to generate the points:

    import numpy as np
    import matplotlib.pyplot as plt
    
    pts = 1000000
    mean = [0.0, 0.0]
    cov = [[1.0,0.0],[0.0,1.0]]
    
    x,y = np.random.multivariate_normal(mean, cov, pts).T
    plt.hist2d(x, y, bins=50, cmap=plt.cm.jet)
    plt.show()
    

    Output:

提交回复
热议问题