2

I need to plot data by using Axes3D of python. 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()

enter image description here

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:

mat

What must I change in my code to have a figure like the second figure please?

1
  • Have you tried to adapt the matplotlib example? If yes, why did it fail? Commented Dec 9, 2018 at 22:51

1 Answer 1

3

Unfortunately you can't currently get transparent bars in any matplotlib version >=2 (Issue #10237).

Apart, the problem is that you got the role of x,y,z and dx, dy, dz wrong somehow. 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 = fig.add_subplot(projection='3d')
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()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.