简体   繁体   English

如何在python中使用Axes3D绘制数据?

[英]How to plot data with Axes3D in python?

I need to plot data by using Axes3D of python. 我需要使用python的Axes3D绘制数据。 This is my code: 这是我的代码:

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

x = [74, 74, 74, 74, 74, 74, 74, 74, 192, 74]
y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
z =  [1455, 1219, 1240, 1338, 1276, 1298, 1292, 1157, 486, 1388]
dx = np.ones(10)
dy = np.ones(10)
dz = [0,1,2,3,4,5,6,7,8,9]


fig = plt.figure()
ax = Axes3D(fig)
ax.bar3d(x, y, z, dx, dy, dz, color='#00ceaa')
ax.w_xaxis.set_ticklabels(x)
ax.w_yaxis.set_ticklabels(y)
ax.set_title("Data Analysis ")
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')


plt.show()

在此处输入图片说明

My problem is that I expect to have a large bars that must look like histogram. 我的问题是我希望有一个看起来像直方图的大条形图。 But I don't have that result, That means it looks like this: 但是我没有那个结果,这意味着它看起来像这样:

垫

What must I change in my code to have a figure like the second figure please? 我必须在代码中进行哪些更改才能使图形像第二个图形一样?

Unfortunately you can't currently get transparent bars in any matplotlib version >=2 ( Issue #10237 ). 不幸的是,您目前无法在任何Matplotlib版本> = 2( Issue#10237 )中获得透明条。

Apart, the problem is that you got the role of x,y,z and dx, dy, dz wrong somehow. 除此之外,问题是您以某种方式错了x,y,z和dx,dy,dz的角色。 I suppose you meant something like 我想你的意思是

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

x = [74, 74, 74, 74, 74, 74, 74, 74, 192, 74]
y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
z =  np.zeros(10)
dx = np.ones(10)*10
dy = np.ones(10)
dz = [1455, 1219, 1240, 1338, 1276, 1298, 1292, 1157, 486, 1388]

fig = plt.figure()
ax = Axes3D(fig)
bar3d = ax.bar3d(x, y, z, dx, dy, dz, color='C0')

ax.set_title("Data Analysis ")
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')

plt.show()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM