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

标签 python matplotlib

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

这是代码

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/

相关文章:

python - Kivy:如何在等待显示另一个小部件时显示一个小部件(均从同一事件调用)

python - 全屏 matplotlib 数字

python-2.7 - 如何将 matplotlib ax range 设置为正值并围绕某个值进行镜像

python - 减少 sns.pairplot() 中的绘图数量

tk 中的 Python 可滚动小部件

python - 如何使用Python中的现有列以其他列为条件创建新列

python空参数

python - AttributeError functools.total_ordering

python - 如何在pyplot中自动标注最大值

python - Matplotlib subplot2grid 在 pandas 0.16.1 中绘制 IndexError