Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting parallel prospective in mlab/mayavi/python

I have a code in python to render a few spheres in python that looks like this:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import random
import mayavi
from mayavi import mlab

N = 4;
diams = .4*np.ones([N]);
xvals = np.arange(N);
yvals = np.zeros(N);
zvals = np.zeros(N);
pts = mlab.points3d(xvals, yvals, zvals, diams, scale_factor=1,transparent=True)

mlab.show()

The default view of the figure adds distortion based on the camera position (farther spheres smaller). I'd like to set the to parallel projection (farther spheres same size) by some command so it renders like this automatically.

I didn't find a straightforward solution with google or the documentation. Thanks!

like image 654
anon01 Avatar asked Sep 11 '15 02:09

anon01


1 Answers

Try setting fig.scene.parallel_projection = True or mlab.gcf().scene.parallel_projection = True in your case.

As a quick example, compare (zoomed in to magnify differences):

import numpy as np
from mayavi import mlab

np.random.seed(1977)
x, y, z = np.random.random((3, 10))

mlab.points3d(x, y, z)
mlab.show()

enter image description here

And when we set an orthogonal projection:

import numpy as np
from mayavi import mlab

np.random.seed(1977)
x, y, z = np.random.random((3, 10))

mlab.points3d(x, y, z)
mlab.gcf().scene.parallel_projection = True
mlab.show()

enter image description here

like image 133
Joe Kington Avatar answered Oct 26 '22 06:10

Joe Kington