我刚学习Matplotlib,所以我直接进行立体可视化.我已经建立了镜子来观看屏幕,并且让左右图形以交互方式更新正确的距离.
我现在需要做的是询问一个轴的方向,设置另一个轴的方向.我有RFTM,并做了帮助(Axes3D.function),不幸的是文档看起来有点薄,而且不一致.
到目前为止,我发现的唯一的Axes3D调用是set_init(azim =,elev =)和get_proj(),它返回4x4变换矩阵.
现在get_proj说 - 引用pdf,这是与docstring相同的文本
get_proj()
Create the projection matrix from the current viewing position.
elev stores the elevation angle in the z plane
azim stores the azimuth angle in the x,y plane
dist is the distance of the eye viewing point from the object point.
Run Code Online (Sandbox Code Playgroud)
......没有描述4x4矩阵.
我可以尝试对矩阵中的值进行反向工程以给出azim和elev,但逆向工程总是感觉不对,特别是对于广泛使用的库.我也没有找到任何设置dist的功能.我根据其中一个示例编写了一个简短的脚本来设置和查询查看位置.
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure()
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(x, y, z, label='parametric curve')
fig.canvas.draw()
with open('dump_proj.txt','wt') as fout:
for e in range(0, 61, 30):
for a in range(0, 61, 30):
fout.write('setting azimuth to {0}, elevation to {1}\n'.format(a, e))
ax.view_init(azim=a, elev=e)
fig.canvas.draw()
d=ax.get_proj()
for row in d:
fout.write('{0:8.4f} {1:8.4f} {2:8.4f} {3:8.4f} \n'.format(*row))
fout.write('\n')
Run Code Online (Sandbox Code Playgroud)
此处显示了已保存文件的示例部分
将方位角设置为60,高程设置为30
-0.1060 0.0604 0.0000 -0.0519
-0.0306 -0.0523 0.2165 0.0450
0.0000 0.0000 0.0000 -10.0000
-0.0530 -0.0906 -0.1250 10.0779
我猜这10就像是观看距离.我非常希望使用30或60度角的0.5或0.866条目,但它看起来并不那么简单.
是否有一些我缺少的功能,设置距离,或获得高程和方位角?或者我缺少的文档,告诉我如何构建4x4 proj矩阵?
我有一个解决方法,最终可能会给我更好的计时,那就是使用另一个控件设置方位角和高程,然后使用它来查看左眼和右眼的view_init().但我首先想从其中一个轴获取方向.
另一个问题,如何
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
Run Code Online (Sandbox Code Playgroud)
工作?我只是慢慢地掌握OO方法,这似乎是神奇的.Axes3D的导入是否在幕后做了改变pyplot导入的事情?如果它是重写方法,我会非常期望在2D内容之后导入3D内容.我想如果一切正常,那一定是好的,但我不明白.
| 归档时间: |
|
| 查看次数: |
3716 次 |
| 最近记录: |