Set / get 3D viewing direction for Matplotlib Axes3D

I'm just learning Matplotlib, so I'm going straight for stereo visualization. I have already built mirrors for viewing the screen and got left and right shapes, interactively changing the distance in the distance.

Now I need to interrogate the orientation of one axis to set the orientation of the other. I have RFTM'd and help (Axes3D.function), and unfortunately the documentation seems a bit thin and inconsistent.

The only Axes3D calls I've found so far that set / get the viewing orientation are view_init (azim =, elev =) and get_proj (), which return a 4x4 transform matrix.

Now get_proj says - quoting from pdf, which is the same text as 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. 

... which does not describe a 4x4 matrix.

I could try redesigning the values โ€‹โ€‹in the matrix to give me the azim and bodice, but reverse engineering always seems wrong, especially for the widely used library. I also did not find the function to install dist. I wrote a short script based on one example for setting and polling viewing positions.

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

A sample portion of the saved file is shown here.

azimuth setting up to 60, height up to 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.0709

I would suggest that 10 is something like a viewing distance. I rather hoped for 0.5 or 0.866 records using angles of 30 and 60 degrees, but it doesn't look so simple.

Are there some functions that I donโ€™t have enough to set the distance, or get altitude and azimuth? Or bits of documentation that I miss tell us how the 4x4 proxy matrix is โ€‹โ€‹built?

I have a workaround that could ultimately give me a better time, and to use another control to set the azimuth and height, and then use it for view_init () for both the left and right axes of the eyes. But I would prefer to get the orientation from one of the axes in the first place.

Another question how

 from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt 

work? I am only slowly versed in OO methods, and this seems to work by magic. Does Axes3D import something behind the scenes to change pyplot import? I would not expect to import 3D material after 2D material if this were a redefinition method. I think if everything works, everything should be fine, but I donโ€™t understand how to do it.

+7
source share
1 answer

Doh, what I did not do is look at the dir () instance of the Axes3D class. And here they are: .azim, .elev and .dist.

+11
source

All Articles