3D条形图演示

有关如何使用和不使用着色绘制3D条形图的基本演示。

3D条形图演示

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. # This import registers the 3D projection, but is otherwise unused.
  4. from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
  5. # setup the figure and axes
  6. fig = plt.figure(figsize=(8, 3))
  7. ax1 = fig.add_subplot(121, projection='3d')
  8. ax2 = fig.add_subplot(122, projection='3d')
  9. # fake data
  10. _x = np.arange(4)
  11. _y = np.arange(5)
  12. _xx, _yy = np.meshgrid(_x, _y)
  13. x, y = _xx.ravel(), _yy.ravel()
  14. top = x + y
  15. bottom = np.zeros_like(top)
  16. width = depth = 1
  17. ax1.bar3d(x, y, bottom, width, depth, top, shade=True)
  18. ax1.set_title('Shaded')
  19. ax2.bar3d(x, y, bottom, width, depth, top, shade=False)
  20. ax2.set_title('Not Shaded')
  21. plt.show()

下载这个示例