import numpy as np import matplotlib.pyplot as plt r = np.arange(0, 3, 0.002) theta = 2 * np.pi * r fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(111, projection='polar') # 绘制极坐标螺旋线 ax.plot(theta, r, label='Archimedean spiral') # 设置极坐标刻度 ax.set_rticks([0.5, 1, 1.5, 2, 2.5, 3, 4]) # 添加交点的标记 ax.annotate('a polar annotation', xy=(5*np.pi/4, 0.6), xytext=(np.pi/2, -0.5), arrowprops=dict(arrowstyle='->', connectionstyle='arc3', color='red')) ax.text(np.pi/2, 0.9, '1.0', ha='center', va='center') ax.text(np.pi/2, -0.1, '0.0', ha='center', va='center') ax.plot(5*np.pi/4, 0.6, 'ro') # 添加起点和终点的标记 ax.annotate('Start Here', xy=(0, 0), xytext=(0.1, 1.2), arrowprops=dict(facecolor='black', shrink=0.05)) ax.annotate('End Here', xy=(10*np.pi, 10*np.pi), xytext=(9.5, 9.5), arrowprops=dict(facecolor='black', shrink=0.05)) # 添加图例 ax.legend() plt.show()修正代码