Python 如何绘制二维点的连续热图

Python 如何绘制二维点的连续热图,python,matplotlib,Python,Matplotlib,我有这样一个数据集: import numpy as np x, y = np.meshgrid(np.arange(0, 100, 1), np.arange(0, 100, 1)) loc = np.array([x.flatten(), y.flatten()]).T vals = np.random.rand(10000).reshape(100, 100) 或者使用更结构化的分布: vals = mvn.pdf(loc,[50, 24], np.array([[ 5 , -2 ],

我有这样一个数据集:

import numpy as np
x, y = np.meshgrid(np.arange(0, 100, 1), np.arange(0, 100, 1))
loc = np.array([x.flatten(), y.flatten()]).T
vals = np.random.rand(10000).reshape(100, 100)
或者使用更结构化的分布:

vals = mvn.pdf(loc,[50, 24], np.array([[ 5 , -2 ], [-2 ,  7]])) + \
       mvn.pdf(loc, [20, 60], np.array([[20, 30], [40, 90]])) + \
       0.4
vals = vals / max(vals)
vals = vals.reshape(100, 100)
我的所有值都在[0,1]刻度上。我想以连续的方式绘制VAL的分布。我想到的是一种热图,它会根据一个值不断改变颜色。就我所知,我唯一的想法是plt.contour,然而,我对结果并不满意


matplotlib
中我有哪些备选方案?如何在第二个
VAL
的情况下使其“更连续”?

我最近在二维图形中使用了这个程序。如果要设置动画,需要执行以下操作:

import random #I used this for my data

import matplotlib.pyplot as plt   #Used to plot data
from matplotlib.animation import FuncAnimation   #Animation function from matplotlib

x_vals = list()  #Your data my x y preset lists
y_vals = list()

def Animate(I): #Create an animation function
    #Below I create my randomized data over time
    x_vals.append(random.randint(0,5))
    y_vals.append(random.randint(0,5))
    #The following create the graph
    plt.cla() #This clears the graph color such that you don't have issues with randomized colors
    plt.plot(x_vals, y_vals) #This plots the data, use whatever function you want for this

ani = FuncAnimation(plt.gcf(), Animate, interval=100) #The following "Animates" the graph
#Your interval is in ms

plt.tight_layout() #Nicer layout for data, likely not needed in your code
plt.show() #Shows the plot

我不明白。对数据进行平滑处理然后进行绘图是否有效?对于均匀的随机分布,我看不出您的确切期望值。注意:如果您想要更好的“热图”,可以使用camp,我为RAMPIS-C模型提供的一些3d绘图代码如下:注:如果您想要更好的“热图”,可以使用camp,我为我的RAMPIS-C模型提供的一些3d图形代码如下:surf=ax。plot_surface(X,Y,Z,cmap=cm.coolwarm,linewidth=0,antialiased=False)cmap将创建一个热图效果。对于创建曲面,您可能需要创建一个3d图形,我不知道matplotlib如何创建一个2d图形,其精度类似于等高线的热图,因此使用3d图形可能是matplotlib中的唯一选择