如何在python3中绘制3D轴

时间:2019-11-07 12:15:33

标签: python-3.x matplotlib

我运行了以下脚本来绘制3d轴:

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

fig = plt.figure(figsize=[10,3])
ax = fig.gca(projection = '3d')

# some settings
vleng = 5
aleng = vleng/3.

p = np.array([vleng, 0, 0])
q = np.array([0, vleng, 0])
r = np.array([0, 0, vleng])

ax.plot(*np.vstack([[0,0,0], p]).T, color='black')
ax.plot(*np.vstack([[0,0,0], q]).T, color='black')
ax.plot(*np.vstack([[0,0,0], r]).T, color='black')

# plotting arrow at terminal of the lines
ax.quiver(vleng, 0, 0, aleng, 0, 0,  \
          length=0.5, arrow_length_ratio=0.5, color='black')
ax.quiver(0, vleng, 0, 0, aleng, 0, \
          length=0.5, arrow_length_ratio=0.5, color='black')
ax.quiver(0, 0, vleng, 0, 0, aleng, \
          length=0.5, arrow_length_ratio=0.5, color='black')

ax.text3D(vleng+1.5, 0, 0, 'X')
ax.text3D(0, vleng+1.0, 0, 'y')
ax.text3D(0, 0, vleng+1.0, 'z')

ax.azim = 8    # y rotation (default=270)
ax.elev = 15    # x rotation (default=0)
ax.dist = 10    # zoom (define perspective)

ax.set_axis_off( )  # hide all grid


plt.show()
plt.savefig('axes.pdf')

它给出:

Figure

如何设置y轴的长度?我无法设定。我尝试对代码进行几次更改,但未成功。

0 个答案:

没有答案