我正在使用 matplotlib 构建一个 3D 散点图,但无法使生成的图形具有所有 3 个轴的共同原点。我怎样才能做到这一点?
我的代码(到目前为止),我还没有为轴规范实现任何定义,因为我对 Python 很陌生:
from mpl_toolkits.mplot3d.axes3d import Axes3D
import matplotlib.pyplot as plt
# imports specific to the plots in this example
import numpy as np
from matplotlib import cm
from mpl_toolkits.mplot3d.axes3d import get_test_data
def randrange(n, vmin, vmax):
return (vmax-vmin)*np.random.rand(n) + vmin
# Same as wide as it is tall.
fig = plt.figure(figsize=plt.figaspect(1.0))
ax = fig.add_subplot(111, projection='3d')
n = 512
xs = np.random.randint(0, 10, size=n)
ys = np.random.randint(0, 10, size=n)
zs = np.random.randint(0, 10, size=n)
colors = np.random.randint(0, 10, size=n)
scat = ax.scatter(xs, ys, zs, c=colors, marker='o')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
fig.colorbar(scat, shrink=0.5, aspect=10)
plt.show()