forked from Visualize-ML/Book4_Power-of-Matrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bk4_Ch3_02.py
53 lines (41 loc) · 1.34 KB
/
Bk4_Ch3_02.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
###############
# Authored by Weisheng Jiang
# Book 4 | From Basic Arithmetic to Machine Learning
# Published and copyrighted by Tsinghua University Press
# Beijing, China, 2022
###############
# Bk4_Ch3_02.py
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sns
u = [0,0,4, 3]
v = [0,0,-2,4]
u_bis = [4,3,v[2],v[3]]
w = [0,0,2,7]
fig, ax = plt.subplots()
plt.quiver([u[0], u_bis[0], w[0]],
[u[1], u_bis[1], w[1]],
[u[2], u_bis[2], w[2]],
[u[3], u_bis[3], w[3]],
angles='xy', scale_units='xy',
scale=1, color=sns.color_palette())
plt.axvline(x=0, color='grey')
plt.axhline(y=0, color='grey')
plt.text(3, 1, r'$||\vec{u}||_2$',
color=sns.color_palette()[0], size=12,
ha='center',va='center')
plt.text(3, 6, r'$||\vec{v}||_2$',
color=sns.color_palette()[1], size=12,
ha='center',va='center')
plt.text(0, 4, r'$||\vec{u}+\vec{v}||_2$',
color=sns.color_palette()[2], size=12,
ha='center',va='center')
plt.ylabel('$x_2$')
plt.xlabel('$x_1$')
plt.axis('scaled')
ax.set_xticks(np.arange(-2,8 + 1))
ax.set_yticks(np.arange(-2,8 + 1))
ax.set_xlim(-2, 8)
ax.set_ylim(-2, 8)
ax.grid(linestyle='--', linewidth=0.25, color=[0.5,0.5,0.5])
# reference: Essential Math for Data Science