From bcbe2bd9dd1d87878e384e43ae2d319a64fc3e40 Mon Sep 17 00:00:00 2001 From: 2509165005 <2509165005@student.edu.cn> Date: Thu, 23 Apr 2026 16:00:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9AX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 作业.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 作业.py diff --git a/作业.py b/作业.py new file mode 100644 index 0000000..0d29466 --- /dev/null +++ b/作业.py @@ -0,0 +1,36 @@ +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") \ No newline at end of file