1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt import numpy as np
np.random.seed(19680801)
fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x, y = np.random.rand(2, 100) * 4 hist, xedges, yedges = np.histogram2d(x, y, bins=4, range=[[0, 4], [0, 4]])
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25, indexing="ij") xpos = xpos.ravel() ypos = ypos.ravel() zpos = 0
dx = dy = 0.5 * np.ones_like(zpos) dz = hist.ravel()
ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b', zsort='average')
plt.show()
|