2013-03-17 82 views
1

我想繪製每個基地在x,y座標和高度等於z值的酒吧。下面的代碼似乎沒有正確捕獲我的X軸,我不知道爲什麼。matplotlib 3dbars:與軸的故障

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

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 

x = [0.0245, 0.015, 0.0245, 0.0285, 0.0245, 0.0245] 
y = [0.0024, 0.0075, 0.0095, 0.01, 0.008, 0.0018] 
z = [11.71, 2.09, 2.49, 2.05, 2.72, 22.55] 

ax.bar(x, y, z, zdir='z', color='g', alpha=.8) 

plt.show() 

回答

1

檢查參數,你說你想要的高度等於z值,但是你傳遞的是y的高度。這是更好的,使用bar3d

enter image description here

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

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 

x = [0.0245, 0.015, 0.0245, 0.0285, 0.0245, 0.0245] 
y = [0.0024, 0.0075, 0.0095, 0.01, 0.008, 0.0018] 
z = [11.71, 2.09, 2.49, 2.05, 2.72, 22.55] 

ax.bar3d(x, y, [0]*6, 0.001, 0.001, z) 

ax.set_xlabel('x') 
ax.set_ylabel('y') 
ax.set_zlabel('z') 

plt.show()