pylab 3D散点图与绘制的数据的二维投影 [英] pylab 3d scatter plots with 2d projections of plotted data

查看:2289
本文介绍了pylab 3D散点图与绘制的数据的二维投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的3D散点图,但我想也显示此数据的2D投影上的数字相同。 这将允许显示两个那些3个变量,可能是很难看到的3D绘图之间的相关性。

我记得看到在此之前的地方,但没能再次找到它。

下面是一些玩具例子:

  X = np.random.random(100)
Y = np.random.random(100)
Z =的sin(x ** 2 + Y ** 2)

图=图()
AX = fig.add_subplot(111,投影='3D')
ax.scatter(X,Y,Z)
 

解决方案

您可以使用剧情方法并指定<$ C添加三维散数据的二维投影$ C> zdir :

 进口numpy的为NP
进口matplotlib.pyplot为PLT

X = np.random.random(100)
Y = np.random.random(100)
Z = np.sin(3 * X ** 2 + Y ** 2)

图= plt.figure()
AX = fig.add_subplot(111,投影='3D')
ax.scatter(X,Y,Z)

ax.plot(X,Z,R +,zdir ='y'的,ZS = 1.5)
ax.plot(Y,Z,G +,zdir ='×',ZS = -0.5)
ax.plot(X,Y​​,K +,zdir ='Z',ZS = -1.5)

ax.set_xlim([ -  0.5,1.5])
ax.set_ylim([ -  0.5,1.5])
ax.set_zlim([ -  1.5,1.5])

plt.show()
 

I am trying to create a simple 3D scatter plot but I want to also show a 2D projection of this data on the same figure. This would allow to show a correlation between two of those 3 variables that might be hard to see in a 3D plot.

I remember seeing this somewhere before but was not able to find it again.

Here is some toy example:

x= np.random.random(100)
y= np.random.random(100)
z= sin(x**2+y**2)

fig= figure()
ax= fig.add_subplot(111, projection= '3d')
ax.scatter(x,y,z)

解决方案

You can add 2D projections of your 3D scatter data by using the plot method and specifying zdir:

import numpy as np
import matplotlib.pyplot as plt

x= np.random.random(100)
y= np.random.random(100)
z= np.sin(3*x**2+y**2)

fig= plt.figure()
ax= fig.add_subplot(111, projection= '3d')
ax.scatter(x,y,z)

ax.plot(x, z, 'r+', zdir='y', zs=1.5)
ax.plot(y, z, 'g+', zdir='x', zs=-0.5)
ax.plot(x, y, 'k+', zdir='z', zs=-1.5)

ax.set_xlim([-0.5, 1.5])
ax.set_ylim([-0.5, 1.5])
ax.set_zlim([-1.5, 1.5])

plt.show()

这篇关于pylab 3D散点图与绘制的数据的二维投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆