Search code examples
pythonmatplotlibprojection

how to change matplotlib 3d plot to side-view?


If there is arrays of x, y, and z coordinates. I don't mean to show a static 2d plot, which can be drawn by

plot(x, y)

I mean

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot(x, y, z, label='parametric curve')

plt.show()

which matplotlib function can change the view to side-view? So that I can add buttons for the matplotlib GUI, on which when user click, the 3d plot will be drawn as top-view/left-view/... and the user can still use mouse to rotate the plot in a 3d way later, just like what we can do in CAD software.

thanks


Solution

  • If I understand your question, you are looking for the function Axes3D.view_init

    view_init(elev=None, azim=None)

    Set the elevation and azimuth of the axes.

    This can be used to rotate the axes programatically.

    ‘elev’ stores the elevation angle in the z plane. ‘azim’ stores the azimuth angle in the x,y plane.

    if elev or azim are None (default), then the initial value is used which was specified in the Axes3D constructor.