我有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()