3

This is my first time using stackoverflow. mplot3d seems to automatically centre the camera around the centre of mass of everything that has been plotted on the axis such that everything is always in view. In my basic example I plot a sphere of radius 10 centred at (0, 0, 10), mplot3d automatically centres the camera at (0, 0, 10) so the sphere always fills the plot. Is there any way I can disable this behavour so the camera remains centred at (0, 0, 0) or better still, manually lock the camera centre position to a set of coordinates?

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

fig = plt.figure(figsize=(5,5))
sphere = fig.add_subplot(111, projection="3d")

phi = np.linspace(0, 2 * np.pi, 20)
theta = np.linspace(0, np.pi, 20)

xpt = 10 * np.outer(np.cos(phi), np.sin(theta))
ypt = 10 * np.outer(np.sin(phi), np.sin(theta))
zpt = 10 * np.outer(np.ones(np.size(phi)), np.cos(theta))

zpt = zpt+10

sphere.plot_surface(xpt, ypt, zpt, color="#00f3ff", alpha=1)

sphere.view_init(azim=0, elev=0)
sphere.disable_mouse_rotation()

plt.show()

Output demo:

enter image description here

If not can anybody suggest any other packages with similar 3d plotting capabilities that will give me more control?

dm2
  • 4,053
  • 3
  • 17
  • 28
Billy Vale
  • 31
  • 2
  • do you want to move the axes object within the figure? change the extent of the of the z-axis? – Paul H Jul 30 '20 at 13:42
  • I don't get it. Did you try changing `azim` and `elev` values. Camera centre at (0,0,0) will make the camera go inside the sphere i guess. If you want to just change camera angle and set it at some point just use like `sphere.view_init(azim=0, elev=50)` . If you want to change the Y-axis ( as in the pic ), remove / comment`zpt = zpt+10` . All the axes center will be at (0,0,0) i guess. The figure can be rotated around that. – Tanmaya Meher Jul 30 '20 at 15:14
  • Let me try to clarify: By camera centre I mean the point that the camera rotates around when I change the `azim` and `elev` angles, or rotate it with the mouse. If the camera is centred at (0,0,0) then ideally the sphere will only occupy the top half of the figure and the bottom half will be emtpy axis with nothing plotted on it.I'm trying to produce an animation where data that has been plotted stays in the same place in the figure, the issue is as I plot more data the camera moves by itself. I should still be able to see everything in the axis given that `sphere.dist` is large enough – Billy Vale Jul 31 '20 at 08:36

0 Answers0