我试图在Linux中使用matplotlib和python2.7构建一个3d图形。但图像的对齐设置不正确。
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = list(xrange(0,51))
y = list(xrange(0,9))
X, Y = np.meshgrid(x, y)
zs = np.array([fun(x,y) for x,y in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)
ax.scatter(X, Y, Z)
plt.yticks(np.arange(0,9), ['0.8', '1.0', '1.2', '1.4', '1.6','1.8','2.0','2.2','2.4'])
plt.xticks(np.arange(0,51, 10.0))
plt.gray()
ax.set_ylabel('Frequency (GHz)')
ax.set_xlabel('Clamping States')
ax.set_zlabel('Power(W)')
plt.savefig('final' + '.jpg', bbox_inches='tight', pad_inches=0.2,dpi=100)
plt.clf()
def fun(x, y):
return power_matrix[x][y]
power_matrix = [[] for a in range(0, len(clamp_ranges))]
我究竟做错了什么?为什么对齐不正确?