Python 3D打印显示错误的轴标签(X轴具有Y轴名称,Y轴具有X轴名称)

Python 3D打印显示错误的轴标签(X轴具有Y轴名称,Y轴具有X轴名称),python,matplotlib,plot,Python,Matplotlib,Plot,我想创建3D直方图,但我不知道为什么X轴有Y标签,Y轴有X轴。怎么了 xAmplitudes = ([0 for i, j in zip(x, width)]) yAmplitudes = centre_y x = np.array(xAmplitudes) #turn x,y data into numpy arrays y = np.array(yAmplitudes) fig = plt.figure() #create a canvas, tell matpl

我想创建3D直方图,但我不知道为什么X轴有Y标签,Y轴有X轴。怎么了

xAmplitudes = ([0 for i, j in zip(x, width)])
yAmplitudes = centre_y 

x = np.array(xAmplitudes)   #turn x,y data into numpy arrays
y = np.array(yAmplitudes)

fig = plt.figure()          #create a canvas, tell matplotlib it's 3d
ax = fig.add_subplot(111, projection='3d')


#make histogram stuff - set bins - I choose 50x50 because I have a lot of data
hist, xedges, yedges = np.histogram2d(x, y, bins=(50,50))
xpos, ypos = np.meshgrid(xedges[:-1]+xedges[1:], yedges[:-1]+yedges[1:])

xpos = xpos.flatten()/2.
ypos = ypos.flatten()/2.
zpos = np.zeros_like (xpos)

dx = xedges [1] - xedges [0]
dy = yedges [1] - yedges [0]
dz = hist.flatten()

ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color=blue, zsort='average')
plt.xlabel("X ")
plt.ylabel("Y ")

注意文档中关于输出阵列的内容:

“样本x和y的二维柱状图。x中的值沿第一维度进行了直方图分析,y中的值沿第二维度进行了直方图分析。”

这意味着您可能希望转置生成的数组,如

dz = hist.T.flatten()