Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import matplotlib.pyplot as plt
- import matplotlib.ticker as ticker
- from mpl_toolkits.mplot3d import Axes3D
- from matplotlib.widgets import Button
- # Оси координат #
- def draw_axis(ax):
- ax_max = 7
- ax_min = 0
- ax.set_xlim(ax_min, ax_max)
- ax.set_ylim(ax_min, ax_max)
- ax.set_zlim(ax_min, ax_max)
- ax_dx = 1
- ax.xaxis.set_major_locator(ticker.MultipleLocator(ax_dx))
- ax.yaxis.set_major_locator(ticker.MultipleLocator(ax_dx))
- ax.zaxis.set_major_locator(ticker.MultipleLocator(ax_dx))
- ax_col = 'k'
- ax.quiver(ax_min, 0, 0, ax_max, 0, 0, color=ax_col, lw=1.5,
- arrow_length_ratio=0.1)
- ax.quiver(0, ax_min, 0, 0, ax_max, 0, color=ax_col, lw=1.5,
- arrow_length_ratio=0.1)
- ax.quiver(0, 0, ax_min, 0, 0, ax_max, color=ax_col, lw=1.5,
- arrow_length_ratio=0.1)
- ax.text(ax_max, 0, 0.15, 'x', size=16, color=ax_col)
- ax.text(0, ax_max, 0.15, 'y', size=16, color=ax_col)
- ax.text(0, 0, ax_max, 'z', size=16, color=ax_col)
- ax.text(0, 0, 0.15, '0', size=16, color=ax_col)
- # Нарисовать точки #
- def draw_points(ax, points):
- for p in points:
- ax.scatter3D(p[1], p[2], p[3], c='r')
- ax.text(p[1], p[2], p[3]+0.15, p[0], size=18, color='r')
- # Нарисовать проекции точек #
- def draw_projections(ax, points):
- for point in points:
- # на плоскость x0y
- ax.plot([point[1], point[1]], [point[2], point[2]], [point[3], 0],
- ls='--', c='m')
- ax.plot([point[1], point[1]], [point[2], 0], [0, 0],
- ls='--', c='m')
- ax.plot([point[1], 0], [point[2], point[2]], [0, 0],
- ls='--', c='m')
- ax.text(point[1], 0, 0.15, point[1], size=16, color='m')
- ax.text(0, point[2], 0.15, point[2], size=16, color='m')
- # на плоскость x0z
- ax.plot([point[1], point[1]], [point[2], 0], [point[3], point[3]],
- ls='--', c='m')
- ax.plot([point[1], point[1]], [0, 0], [point[3], 0],
- ls='--', c='m')
- ax.plot([point[1], 0], [0, 0], [point[3], point[3]],
- ls='--', c='m')
- ax.text(0, 0, point[3]+0.15, point[3], size=16, color='m')
- # на плоскость y0z
- ax.plot([point[1], 0], [point[2], point[2]], [point[3], point[3]],
- ls='--', c='m')
- ax.plot([0, 0], [point[2], point[2]], [point[3], 0],
- ls='--', c='m')
- ax.plot([0, 0], [point[2], 0], [point[3], point[3]],
- ls='--', c='m')
- plt.draw()
- if __name__ == '__main__':
- def click_1(event):
- draw_projections(ax, points)
- fig = plt.figure()
- ax = Axes3D(fig)
- ax.view_init(azim=36, elev=20)
- points = [['A', 3, 4, 5]]
- #ax.set_axis_off()
- ax.grid()
- draw_axis(ax)
- draw_points(ax, points)
- axes_button_1 = plt.axes([0.1, 0.05, 0.1, 0.1])
- button_1 = Button(axes_button_1, '#1')
- button_1.on_clicked(click_1)
- plt.show()
Add Comment
Please, Sign In to add comment