From ed8eb9bf2bc032c784abeda903033a3048b56431 Mon Sep 17 00:00:00 2001 From: Guillaume Favelier Date: Thu, 9 Jan 2020 14:29:04 +0100 Subject: [PATCH] MRG: Correct camera view_up when necessary (#7187) * Correct camera view_up when necessary * Handle the case when elevation is None --- mne/viz/backends/_pyvista.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mne/viz/backends/_pyvista.py b/mne/viz/backends/_pyvista.py index b5e01382274..f6305bc1f23 100644 --- a/mne/viz/backends/_pyvista.py +++ b/mne/viz/backends/_pyvista.py @@ -546,12 +546,20 @@ def _set_3d_view(figure, azimuth, elevation, focalpoint, distance): if focalpoint is not None: cen = np.asarray(focalpoint) + # Now calculate the view_up vector of the camera. If the view up is + # close to the 'z' axis, the view plane normal is parallel to the + # camera which is unacceptable, so we use a different view up. + if elevation is None or 5. <= abs(elevation) <= 175.: + view_up = [0, 0, 1] + else: + view_up = [np.sin(phi), np.cos(phi), 0] + position = [ r * np.cos(phi) * np.sin(theta), r * np.sin(phi) * np.sin(theta), r * np.cos(theta)] figure.plotter.camera_position = [ - position, cen, [0, 0, 1]] + position, cen, view_up] def _set_3d_title(figure, title, size=40):