在3d中用z轴密度表示2d数据

时间:2017-02-17 10:54:02

标签: 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()

但他们重叠了很多: enter image description here

我想用另一个轴来表示每个类的密度(所以得到一个3d表示)来得到2个表面;每个类一个,并能够在任何坐标(x,y)上看到每个类的密度。

我该怎么办?

1 个答案:

答案 0 :(得分:0)

我认为这可以帮到你:

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

相关问题