Search code examples
pythonmatplotlibmatplotlib-3d

Changing center of rotation in a 3D plot


I have a 3D line plot in matplotlib, created using the following code:

    def view(self):
        from mpl_toolkits.mplot3d import Axes3D  #noqa
        import matplotlib.pyplot as plt

        ax = plt.figure().gca(projection='3d')
        history = np.array(self.position_history)
        x, y ,z = history[:, 0], history[:, 1], history[:, 2]
        ax.plot(x, y, z)

        plt.show()

Here history is an Mx3 array of points. This works fine and pops up a plot as expected. I am able to click and drag to modify the azimuth and elevation interactively. I am able to zoom by right-clicking and dragging.

However I am wondering if it is possible to modify the center point of the pan and zoom? I would like to zoom into the top-right, and then pan around with the top right as my center of rotation. If you have ever used solidworks or another CAD program, this is the behavior I am after. Is this doable? If not interactively, can I do it programmatically?

And finally, if none of this is possible in matplotlib, is there another library that can accomplish what I want?


Solution

  • I have also run into trouble in the past in terms of customizing mplot3d, rather unsuccessfully..

    And finally, if none of this is possible in matplotlib, is there another library that can accomplish what I want?

    you can do this with mayavi

    here is a relevant stackoverflow answer for customizing how you interact with your plot

    there are also various useful tips and tricks for animating in general and for using mayavi

    (apologies if this isn't useful)