我运行了以下脚本来绘制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')
它给出:
如何设置y轴的长度?我无法设定。我尝试对代码进行几次更改,但未成功。