三维打印显示错误的轴标签(Xaxis有Yaxis名称,Yaxis有Xaxis名称)

2024-10-04 09:19:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建三维直方图,但我不知道为什么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 ")

plot


Tags: datanpfigpltaxarrayhistbins
1条回答
网友
1楼 · 发布于 2024-10-04 09:19:11

注意^{}文档中关于输出数组的内容:

"The bi-dimensional histogram of samples x and y. Values in x are histogrammed along the first dimension and values in y are histogrammed along the second dimension."

这意味着您需要转置结果数组,可能像

dz = hist.T.flatten()

相关问题 更多 >