[英]Line plot with superimposed arrows in matplotlib
我正在嘗試繪制全天的溫度和風速與時間的關系。 我希望做的是將溫度繪制為法線圖。 然后在該小時的每一小時都有一個重疊的箭頭指向當時的風向(北向0度,東向順時針90度,等等。)
您可以嘗試使用matplotlib的注釋 。 通常,與Arrow
和FancyArrow
相比,它不那么令人頭疼:
import numpy as np
import matplotlib.pyplot as plt
time = np.linspace(0,23,24)
temp = np.array([10]*24) + np.random.random(24)*2
wind = np.linspace(0, 270, 24)
fig, ax = plt.subplots()
ax.plot(time, temp, 'o-')
arrow_len = 1.5
for i, theta in enumerate(np.radians(wind)):
dx = arrow_len * np.cos(theta)
dy = arrow_len * np.sin(theta) * ax.get_data_ratio()
x, y = time[i], temp[i]
ax.annotate("",
xy=(x+dx, y+dy), xycoords='data',
xytext=(x, y), textcoords='data',
arrowprops=dict(arrowstyle="-|>")
)
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.