我正在尝试在单位圆中绘制单位向量。
这是代码
vunit = 1/np.sqrt(2)
vec1 = [vunit,vunit]
thetas = np.arange(-np.pi, np.pi, .05)
coordinates = np.vstack((np.cos(thetas),np.sin(thetas)))
plt.figure(figsize = (6,6))
plt.xlim(-3,3)
plt.ylim(-3,3)
plt.scatter(coordinates[0,:],coordinates[1,:],s=.1)
plt.arrow(0, 0, vec1[0], vec1[1], head_width=0.15, color='r')
一切正常,除了箭头在圆圈外。
所以,我把vec1修改的很丑
vec1 = [vunit-.1,vunit-.1]
图形看起来更好,我可以更精细地修改 vec1,但修复似乎很难看。有没有办法优雅地将箭头放在圆圈内
最佳答案
import numpy as np
import matplotlib.pyplot as plt
vunit = 1/np.sqrt(2)
vec1 = [vunit,vunit]
thetas = np.arange(-np.pi, np.pi, .05)
coordinates = np.vstack((np.cos(thetas),np.sin(thetas)))
plt.figure(figsize = (6,6))
plt.xlim(-3,3)
plt.ylim(-3,3)
plt.scatter(coordinates[0,:],coordinates[1,:],s=.1)
plt.arrow(0, 0, vec1[0], vec1[1], head_width=0.15, color='r', length_includes_head=True)
plt.show()
关于python - 有没有办法优雅地在圆圈内画一个箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56843446/