Python 用z轴上的密度表示三维中的二维数据

Python 用z轴上的密度表示三维中的二维数据,python,matplotlib,Python,Matplotlib,我有2D点(轴d1和d2),它们属于两类1和0。 现在,我这样代表他们: scatter(d1_1,d2_1, marker='o', c='b',alpha=0.5) #class 1 scatter(d1_0,d2_0, marker='x', c='r',alpha=0.5) #class 0 xlabel('d1:'+str(d1)) ylabel('d2:'+str(d2)) legend(['meme classe', 'classe differente']) show() 但它

我有2D点(轴d1和d2),它们属于两类1和0。 现在,我这样代表他们:

scatter(d1_1,d2_1, marker='o', c='b',alpha=0.5) #class 1
scatter(d1_0,d2_0, marker='x', c='r',alpha=0.5) #class 0
xlabel('d1:'+str(d1))
ylabel('d2:'+str(d2))
legend(['meme classe', 'classe differente'])
show()
但它们有很多重叠:

我想在另一个坐标轴中表示每个类的密度(因此获得一个3d表示),以获得2个曲面;每个等级一个,并且能够在任何坐标(x,y)处看到每个等级上的密度


我该怎么办?

我想这可以帮助您:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D

x = np.arange(0,10,1)
y = np.arange(0,1,0.2)

xs, ys = np.meshgrid(x, y)
# z = calculate_R(xs, ys)
zs = xs**2 + ys**2

fig = plt.figure()
ax = Axes3D(fig)
ax.plot_surface(xs, ys, zs, rstride=1, cstride=1, cmap='hot')
plt.show()

信用证:David Zwicker

这个例子应该可以指导您:如果您想使用
seaborn
模块,请查看
jointplot
。下面是一个例子: