36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
try:
|
|
plt.rcParams['font.sans-serif'] = ['SimHei', 'Noto Sans CJK SC', 'WenQuanYi Micro Hei']
|
|
plt.rcParams['axes.unicode_minus'] = False
|
|
except:
|
|
pass
|
|
|
|
fig, ax = plt.subplots(figsize=(8, 8))
|
|
|
|
vectors = {
|
|
'A = [2, 3]': np.array([2, 3]),
|
|
'B = [4, 1]': np.array([4, 1]),
|
|
'C = [1, 1]': np.array([1, 1]),
|
|
}
|
|
|
|
colors = ['red', 'blue', 'green']
|
|
for (name, vec), color in zip(vectors.items(), colors):
|
|
ax.annotate('', xy=vec, xytext=(0, 0),
|
|
arrowprops=dict(arrowstyle='->', color=color, lw=2))
|
|
ax.text(vec[0]+0.1, vec[1]+0.1, name, fontsize=12, color=color)
|
|
|
|
ax.axhline(y=0, color='black', linewidth=0.5)
|
|
ax.axvline(x=0, color='black', linewidth=0.5)
|
|
|
|
ax.set_xlim(-0.5, 5.5)
|
|
ax.set_ylim(-0.5, 4)
|
|
ax.set_xlabel('x (abscissa)', fontsize=12)
|
|
ax.set_ylabel('y (ordinate)', fontsize=12)
|
|
ax.set_title('2D Vector Visualization', fontsize=14)
|
|
ax.grid(True, alpha=0.3)
|
|
ax.set_aspect('equal')
|
|
|
|
plt.show()
|
|
print("Note: Arrows represent vectors. Endpoint of arrow = vector endpoint") |