本文介绍了使用轮廓在3个平面上绘制3D图的投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的三列目录,我想制作一个它们的3D图加上每个轴的投影作为在其他两个轴的平面中的投影轮廓。到目前为止,我可以使用 matplotlib 进行3D图绘制,该图仍然无法显示数据属性。

I have a three columns catalogue of data and I would like to make a 3D plot of them plus the projection of each axis as a projected contour in the the plane of the other two axises. So far I could make the 3D plot using matplotlib which still doesn't show anything from the properties of the data.

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from numpy import *
data=loadtxt('test.cat')
X=data[:,0]
Y=data[:,1]
Z=data[:,2]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X, Y, Z, c='r', marker='.')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()

我还如何使用 colorbar 在每个平面上绘制数据的投影?

How could I plot the projection of the data in each plane with colorbar as well?

推荐答案

嗯,确实很难显示数据。也许最好沿一个轴创建一些切片并创建一定数量的2D图。但是3D绘图很花哨。我对数据进行了一些处理,像您所做的那样生成了一个3D图,并生成了带有投影的单独图。

hmm, indeed, difficult data to display. Maybe creating some slices along one axis and creating certain number 2D plots would be best. However 3D plots are fancy. I played a bit with the data resulting in one 3D plot as you did and a separate plot with the projections.


  • 点的颜色根据缺少

  • 增加了透明度以给出密度的概念

  • 两个图的保留轴相同


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

data = np.loadtxt('test.cat', skiprows=1)

X=data[:,0]
Y=data[:,1]
Z=data[:,2]

plt.figure()
ax1 = plt.subplot(111,  projection='3d')

ax1.scatter(X, Y, Z, c='b', marker='.', alpha=0.2)
ax1.set_xlabel('X - axis')
ax1.set_ylabel('Y - axis')
ax1.set_zlabel('Z - axis')

plt.figure()
ax2 = plt.subplot(111,  projection='3d')

plt.hot()

cx = np.ones_like(X) * ax1.get_xlim3d()[0]
cy = np.ones_like(X) * ax1.get_ylim3d()[1]
cz = np.ones_like(Z) * ax1.get_zlim3d()[0]

ax2.scatter(X, Y, cz, c=Z,  marker='.', lw=0, alpha=0.2)
ax2.scatter(X, cy, Z, c=-Y, marker='.', lw=0, alpha=0.2)
ax2.scatter(cx, Y, Z, c=X,  marker='.', lw=0, alpha=0.2)
ax2.set_xlim3d(ax1.get_xlim3d())
ax2.set_ylim3d(ax1.get_ylim3d())
ax2.set_zlim3d(ax1.get_zlim3d())
ax2.set_xlabel('X - axis')
ax2.set_ylabel('Y - axis')
ax2.set_zlabel('Z - axis')

这篇关于使用轮廓在3个平面上绘制3D图的投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:45