【问题标题】:Line plot with superimposed arrows in matplotlibmatplotlib中带有叠加箭头的线图
【发布时间】:2018-06-26 15:14:40
【问题描述】:

我正在尝试将一天中的温度和风速绘制为时间的函数。 我希望做的是将温度绘制为正常的折线图。然后每个小时都有一个叠加的箭头指向那个时刻的风向(北方0度,东方顺时针90度等......)

【问题讨论】:

    标签: python matplotlib graph visualization seaborn


    【解决方案1】:

    您可以尝试使用 matplotlib 的 annotate。这通常不像Arrows 和FancyArrows 那样令人头疼:

    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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-24
      相关资源
      最近更新 更多