I am trying to reproduce the plot shown in this stack overflow post with my own data but keep getting the following error
/usr/lib/python3.9/site-packages/matplotlib/transforms.py:1977: RuntimeWarning: invalid value encountered in double_scalars
self._mtx[0, 2] += tx
/usr/lib/python3.9/site-packages/matplotlib/transforms.py:379: RuntimeWarning: invalid value encountered in double_scalars
return (x0, y0, x1 - x0, y1 - y0)
Traceback (most recent call last):
File "./tmp.py", line 32, in <module>
ax.bar(bin_edges, bin_counts, zs=row, zdir="z", alpha=0.8)
File "/usr/lib/python3.9/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 2357, in bar
verts += vs.tolist()
AttributeError: 'list' object has no attribute 'tolist'
I have tried generating 2D bar plots using this data and that works fine (see github issue #19246 for a code snippet).
Code to reproduce the error
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
data = np.load("data.npy")
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
ax.set_xlabel("Value")
ax.set_ylabel("Value Count")
ax.set_zlabel("Step")
# The matrix is a divided into pairs of rows
# Each row starts with an integer (stored as a float) indicating the number of useful data elements on that row (N)
# The integer (N) is then followed by N floats, finally some number (>=0) of zeros finishes off the row
# N, N floats, X zeros
# N, N floats, X zeros
# The first row in each pair contains the bucket counts
# The second row in each pair contains the bucket limits
for row in range(0, data.shape[0], 2):
# Extract histogram data
bin_row_count = int(data[row, 0])
bin_counts = data[row, 1 : bin_row_count + 1]
limit_row_count = int(data[row + 1, 0])
bin_edges = data[row + 1, 1 : limit_row_count + 1]
# Plot the current histogram
ax.bar(bin_edges, bin_counts, zs=row, zdir="z", alpha=0.8)
plt.show()
Data to reproduce error (google drive link)
System information
Operating system: Arch Linux
Matplotlib version: 3.3.3
Matplotlib backend: Qt5Agg
Python version: 3.9.1
Jupyter version (if applicable): N/A
Other libraries: Numpy==1.19.4
All python packages installed using the system package manager