gpt4 book ai didi

python - 有没有办法优雅地在圆圈内画一个箭头

转载 作者:行者123 更新时间:2023-11-28 21:32:17 24 4
gpt4 key购买 nike

我正在尝试在单位圆中绘制单位向量。

这是代码

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')

enter image description here

一切正常,除了箭头在圆圈外。

所以,我把vec1修改的很丑

vec1 = [vunit-.1,vunit-.1]

enter image description here

图形看起来更好,我可以更精细地修改 vec1,但修复似乎很难看。有没有办法优雅地将箭头放在圆圈内

最佳答案

使用length_includes_head=True :

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()

enter image description here

关于python - 有没有办法优雅地在圆圈内画一个箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56843446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com