pylab 3d 散点图,带有绘制数据的 2d 投影 [英] pylab 3d scatter plots with 2d projections of plotted data
本文介绍了pylab 3d 散点图,带有绘制数据的 2d 投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个简单的 3D 散点图,但我还想在同一图上显示此数据的 2D 投影.这将允许显示这 3 个变量中的两个之间的相关性,这在 3D 图中可能很难看到.
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.
这是一些玩具示例:
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)
推荐答案
您可以通过使用 plot
方法并指定 zdir
来添加 3D 散点数据的 2D 投影:
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 散点图,带有绘制数据的 2d 投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文