Guest User

Untitled

a guest
May 20th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import matplotlib.pyplot as plt
  3. import matplotlib.ticker as ticker
  4. from mpl_toolkits.mplot3d import Axes3D
  5. from matplotlib.widgets import Button
  6.  
  7. # Оси координат #
  8. def draw_axis(ax):
  9. ax_max = 7
  10. ax_min = 0
  11. ax.set_xlim(ax_min, ax_max)
  12. ax.set_ylim(ax_min, ax_max)
  13. ax.set_zlim(ax_min, ax_max)
  14. ax_dx = 1
  15. ax.xaxis.set_major_locator(ticker.MultipleLocator(ax_dx))
  16. ax.yaxis.set_major_locator(ticker.MultipleLocator(ax_dx))
  17. ax.zaxis.set_major_locator(ticker.MultipleLocator(ax_dx))
  18. ax_col = 'k'
  19. ax.quiver(ax_min, 0, 0, ax_max, 0, 0, color=ax_col, lw=1.5,
  20. arrow_length_ratio=0.1)
  21. ax.quiver(0, ax_min, 0, 0, ax_max, 0, color=ax_col, lw=1.5,
  22. arrow_length_ratio=0.1)
  23. ax.quiver(0, 0, ax_min, 0, 0, ax_max, color=ax_col, lw=1.5,
  24. arrow_length_ratio=0.1)
  25. ax.text(ax_max, 0, 0.15, 'x', size=16, color=ax_col)
  26. ax.text(0, ax_max, 0.15, 'y', size=16, color=ax_col)
  27. ax.text(0, 0, ax_max, 'z', size=16, color=ax_col)
  28. ax.text(0, 0, 0.15, '0', size=16, color=ax_col)
  29.  
  30.  
  31. # Нарисовать точки #
  32. def draw_points(ax, points):
  33. for p in points:
  34. ax.scatter3D(p[1], p[2], p[3], c='r')
  35. ax.text(p[1], p[2], p[3]+0.15, p[0], size=18, color='r')
  36.  
  37. # Нарисовать проекции точек #
  38. def draw_projections(ax, points):
  39. for point in points:
  40. # на плоскость x0y
  41. ax.plot([point[1], point[1]], [point[2], point[2]], [point[3], 0],
  42. ls='--', c='m')
  43. ax.plot([point[1], point[1]], [point[2], 0], [0, 0],
  44. ls='--', c='m')
  45. ax.plot([point[1], 0], [point[2], point[2]], [0, 0],
  46. ls='--', c='m')
  47. ax.text(point[1], 0, 0.15, point[1], size=16, color='m')
  48. ax.text(0, point[2], 0.15, point[2], size=16, color='m')
  49.  
  50. # на плоскость x0z
  51. ax.plot([point[1], point[1]], [point[2], 0], [point[3], point[3]],
  52. ls='--', c='m')
  53. ax.plot([point[1], point[1]], [0, 0], [point[3], 0],
  54. ls='--', c='m')
  55. ax.plot([point[1], 0], [0, 0], [point[3], point[3]],
  56. ls='--', c='m')
  57. ax.text(0, 0, point[3]+0.15, point[3], size=16, color='m')
  58.  
  59. # на плоскость y0z
  60. ax.plot([point[1], 0], [point[2], point[2]], [point[3], point[3]],
  61. ls='--', c='m')
  62. ax.plot([0, 0], [point[2], point[2]], [point[3], 0],
  63. ls='--', c='m')
  64. ax.plot([0, 0], [point[2], 0], [point[3], point[3]],
  65. ls='--', c='m')
  66. plt.draw()
  67.  
  68.  
  69. if __name__ == '__main__':
  70.  
  71. def click_1(event):
  72. draw_projections(ax, points)
  73.  
  74. fig = plt.figure()
  75. ax = Axes3D(fig)
  76. ax.view_init(azim=36, elev=20)
  77. points = [['A', 3, 4, 5]]
  78.  
  79. #ax.set_axis_off()
  80. ax.grid()
  81. draw_axis(ax)
  82. draw_points(ax, points)
  83. axes_button_1 = plt.axes([0.1, 0.05, 0.1, 0.1])
  84. button_1 = Button(axes_button_1, '#1')
  85. button_1.on_clicked(click_1)
  86. plt.show()
Add Comment
Please, Sign In to add comment