我在绘制箭头方向时遇到了一些问题。我有它们的点(x,y)坐标和角度。我想要做的是根据给定的角度绘制箭头(只是为了显示
点方向作为每个点坐标中的箭头)。在这里,我们应该假设 的坐标'+x', '+y', '-x', '-y' 分别是 90, 0, 270, 180 度 , 分别。
我对Python绘图工具有点陌生。无论我使用 pylab 还是其他一些模块,我仍然不确定是否绘制方向点(基于角度的箭头),或者..仍然不确定。我把以下代码
作为示例以提供更好的描述:
# Inputs:
x = np.array([ 2, 4, 8, 10, 12, 14, 16])
y = np.array([ 5, 10, 15, 20, 25, 30, 35])
angles = np.array([45,275,190,100,280,18,45])
import numpy as np
import scipy as sp
import pylab as pl
def draw_line(x,y,angle):
# First, draw (x,y) coordinate ???
# Second, according to the angle indicate the direction as an arrow ???
最佳答案
您可以使用 matplotlib.pyplot.arrow(x, y, dx, dy, hold=None, **kwargs)
绘制箭头.您似乎遇到困难的部分是定义偏移量 dx
和 dy
给定一个角度和一个箭头长度 r
.对于极坐标,angle
以弧度为单位
dx = r*cos(angle)
dy = r*sin(angle)
让您的
draw_line
函数变为def draw_line(x, y, angle):
r = 1 # or whatever fits you
arrow(x, y, r*cos(angle), r*sin(angle))
这将绘制一个从
(x,y)
开始的箭头在angle
的方向长度为 1
.
关于python-2.7 - 在Python中以(x,y)坐标绘制箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15971768/