簡體   English   中英

matplotlib中帶有疊加箭頭的線圖

[英]Line plot with superimposed arrows in matplotlib

我正在嘗試繪制全天的溫度和風速與時間的關系。 我希望做的是將溫度繪制為法線圖。 然后在該小時的每一小時都有一個重疊的箭頭指向當時的風向(北向0度,東向順時針90度,等等。)

您可以嘗試使用matplotlib的注釋 通常,與ArrowFancyArrow相比,它不那么令人頭疼:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM