Вопрос

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?

Это было полезно?

Решение

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)

Другие советы

Not sure this will do what you need but you can define the center when you first plot. Here, "c_x" is the center of rotation on the x axis and the -/+ 200 defines the axis to be 200 units in both direction. Likewise for y and z.

If you had the user choose the center before plotting, that could work as a crude work around.

http://matplotlib.org/api/axes_api.html?highlight=set_xbound#matplotlib.axes.Axes.set_xbound

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')    
ax.autoscale(enable=False,axis='both')  #you will need this line to change the Z-axis
ax.set_xbound(c_x-200, c_x+200)
ax.set_ybound(c_y-200, c_y+200)
ax.set_zbound(c_z-200, c_z+200)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top