三维中的文字注释

演示在3D绘图上放置文本注释。

显示的功能:

  • 使用具有三种“zdir”值的文本函数:无,轴名称(例如’x’)或方向元组(例如(1,1,0))。
  • 使用带有color关键字的文本功能。
  • 使用text2D函数将文本放在ax对象上的固定位置。

三维中的文字注释示例

  1. # This import registers the 3D projection, but is otherwise unused.
  2. from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
  3. import matplotlib.pyplot as plt
  4. fig = plt.figure()
  5. ax = fig.gca(projection='3d')
  6. # Demo 1: zdir
  7. zdirs = (None, 'x', 'y', 'z', (1, 1, 0), (1, 1, 1))
  8. xs = (1, 4, 4, 9, 4, 1)
  9. ys = (2, 5, 8, 10, 1, 2)
  10. zs = (10, 3, 8, 9, 1, 8)
  11. for zdir, x, y, z in zip(zdirs, xs, ys, zs):
  12. label = '(%d, %d, %d), dir=%s' % (x, y, z, zdir)
  13. ax.text(x, y, z, label, zdir)
  14. # Demo 2: color
  15. ax.text(9, 0, 0, "red", color='red')
  16. # Demo 3: text2D
  17. # Placement 0, 0 would be the bottom left, 1, 1 would be the top right.
  18. ax.text2D(0.05, 0.95, "2D Text", transform=ax.transAxes)
  19. # Tweaking display region and labels
  20. ax.set_xlim(0, 10)
  21. ax.set_ylim(0, 10)
  22. ax.set_zlim(0, 10)
  23. ax.set_xlabel('X axis')
  24. ax.set_ylabel('Y axis')
  25. ax.set_zlabel('Z axis')
  26. plt.show()

下载这个示例