仅在循环中绘制一个箭头

2024-09-29 22:33:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用箭头描绘一系列的风向,箭头的大小取决于风力的大小。但在我的循环中我所能做的就是在另一个箭头上画一个箭头。我只想要一个箭头。 enter image description here

enter image description here

enter image description here

这是我的代码,移动ax=plt.轴()脱离循环没有帮助。你知道吗

import numpy as np
import matplotlib.pyplot as plt 
import math

Dir2013 =np.loadtxt('H:/EMBC/Thesis/Data/Wind/winddir_2013_Westhinder.txt') #wind direction
Vel2013 =np.loadtxt('H:/EMBC/Thesis/Data/Wind/windvel_2013_Westhinder.txt') #wind velocity
Start=[]
Stop=[]
kl=[]
kl2=[]
for i in range (0, len(Dir2013)):
    if Dir2013[i][5]==39:
        Start=i
    if Dir2013[i][5]==154:
        Stop=i  
    if Vel2013[i][6]<0:
        Vel2013[i][6]==0
        kl.append(i)
        kl2.append(Vel2013[i][6])

parts=(len(Dir2013)/365)
Steps=(Stop-Start)/parts

for i in range (Start, Stop,int(parts)): 
    ax = plt.axes()
    ax.set_xlim(left=-3, right=3, emit=True, auto=False)
    ax.set_ylim(bottom=-3, top=3, emit=True, auto=False)
    ax.spines['bottom'].set_color('k')
    ax.spines['top'].set_color('k')
    ax.spines['left'].set_color('k')
    ax.spines['right'].set_color('k')
    ax.tick_params(axis='x', colors='k')
    ax.tick_params(axis='y', colors='k')
    x0, y0 = 0, 0
    radius = Vel2013[i][6]*0.1
    angle_rad = int(Dir2013[i][6])* math.pi / 180  # degrees to radians
    head_length = 0.08
    ax.arrow(x0, y0,
   (radius - head_length) * math.cos(angle_rad),
   (radius - head_length) * math.sin(angle_rad),
   head_width=0.08, head_length=head_length, fc='k', ec='k',width=0.01)
    plt.savefig('ArrowAa%d' %i)
plt.show()

如何在每个图中只绘制一个箭头?


Tags: importnppltmath箭头axstartlength

热门问题