简体   繁体   中英

Representing 2d data in 3d with density on the z axis

I have 2D points (axis d1 and d2) which belong to two classes 1 and 0. For now, I represent them like this:

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()

But they overlapp a lot: 在此处输入图片说明

I would like to represent the density of each classes in an other axe (so get a 3d representation) to get 2 surfaces; one for each class and be able to see the density on each class at any coordinates (x,y).

How can i do ?

I think this could help you:

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()

Credits: David Zwicker

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM