0

I have multiple 1D NumPy arrays with variable sizes and I want to plot their histograms in a 3d plot. The best I can reach was using the following code:

#Histograms

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
nbins = 30
z_array = np.linspace(0,420,22)
for a,z in zip(arrays1, z_array):
    ys = a
    hist, bins = np.histogram(ys, bins=nbins,density=True)
    xs = (bins[:-1] + bins[1:])/0.5
    print(xs.shape)
    ax.bar(xs, hist, zs=z, zdir='y', alpha=0.8)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()

enter image description here

The histograms don't look good and I have no clue how to adjust the bin size and also the spacing in between the histograms.

Omar Kamal
  • 55
  • 1
  • 9
  • I don't understand, what do you mean, 'you have no clue how to adjust the bin size'? You declared `nbins = 30`. What is stopping you from changing that number? – mapf May 09 '20 at 22:43
  • Does this answer your question? [How to plot a 3D histogram with matplotlib/mplot3d?](https://stackoverflow.com/questions/54014645/how-to-plot-a-3d-histogram-with-matplotlib-mplot3d) – mapf May 09 '20 at 22:46
  • If you'd like 3d bars, have a look here: https://matplotlib.org/3.1.1/gallery/mplot3d/hist3d.html – Paddy Harrison May 10 '20 at 10:28

0 Answers0