python - How to rotate a figure in all directions in matplotlib -
i trying rotate figure horizontally in python. mouse able rotate through 1 degree of freedom being able spin figure, example can @ momement:
these movements vertical. able rotate figure in directions, example:
this allow me put figure on side etc. @ moment cannot this, can rotate along 1 degree of freedom.
here code:
from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot plt mpl_toolkits.mplot3d.art3d import poly3dcollection import numpy np import math fig = plt.figure() ax = fig.gca(projection='3d') nphi,nz= 13, 101 r=1 phi = np.linspace(0,360, nphi)/180.0*np.pi z= np.linspace(0,350,nz) cols=[] verts2 = [] in range(len(phi)-1): cp0= r*np.cos(phi[i]) cp1= r*np.cos(phi[i+1]) sp0= r*np.sin(phi[i]) sp1= r*np.sin(phi[i+1]) j in range(len(z)-1): z0=z[j] z1=z[j+1] verts=[] verts.append((cp0, sp0, z0)) verts.append((cp1, sp1, z0)) verts.append((cp1, sp1, z1)) verts.append((cp0, sp0, z1)) verts2.append(verts) col=plt.cm.blues(0.4) cols.append(col) poly3 = poly3dcollection(verts2, facecolor=cols ,edgecolor = "red" ) poly3.set_alpha(0.5) ax.add_collection3d(poly3) ax.set_xlabel('x') ax.set_xlim3d(-3, 3) ax.set_ylabel('y') ax.set_ylim3d(-3, 3) ax.set_zlabel('z') ax.set_zlim3d(0, 300) plt.axis('off') ax.axes.get_xaxis().set_visible(false) ax.axes.get_yaxis().set_visible(false) plt.show()
unfortunately, don't think can; documentation:
‘elev’ stores elevation angle in z plane. ‘azim’ stores azimuth angle in x,y plane
so you've not got 3 degrees of freedom here, because can rotate in xy plane, rather around each axis independently.
it's bit clearer if display axes:
Comments
Post a Comment