0

我有 3 个清单

 def main():
     x = np.arange(0.0,256.0)
     y = np.arange(0.0,256.0)
     Y,X = np.meshgrid(x,y)
     Z = wron(X,Y)
     for i in range(0,256):
         Z[i][0]=0

 def wron(X,Y):
     t=X/Y
     return(abs(t*(t-1)))

我如何获得 X、Y 和 Z 列表的 3d 条形图。其中 X,Y,Z 对应于 x,y,z 轴。

我尝试了以下代码。

 from pylab import *
 import numpy
 from mpl_toolkits.mplot3d import Axes3D

 def main():
   fig=figure()
   ax=Axes3D(fig)
   x=np.arange(0.0,256.0)
   y=np.arange(0.0,256.0)
   Y,X= np.meshgrid(x,y)
   Z=wron(X,Y)
   for i in range(0,256):
     Z[i][0]=0
   ax.bar(X,Y,zs=Z,zdir='y')
   show()
 def wron(X,Y):
   t=X/Y
   return(abs(t*(t-1)))

 if __name__=='__main__':
   main()

但我得到这个错误:

patches = Axes.bar(self, left, height, *args, **kwargs)
 File "/usr/lib/python3/dist-packages/matplotlib/axes.py", line 4887, in bar
 if h<0:
  ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
4

0 回答 0