我有一个给定地点的温度的时间序列。我利用其他数据和遥感进行了一些分析,以确定同一地点森林生长季节的开始和结束。现在我想在第二个x轴上加一些小的水平线,显示生长季节的长度。理想情况下,它看起来应该类似于这。在主x轴为temp的情况下,次级x轴是单个生长季节的静态值,y轴是作为日期时间对象绘制的13年时间周期。基本上,我想要相同的蓝线,但我想要长度由两个日期时间值决定。
我知道axhline()采用y位置参数(这将是生长季节的静态值),而xmin和xmax必须在0到1之间浮动。
我的问题是,如何规范长达13年的(每日)数据,以便为plt.axhline()提供适当的值xmin和xmax值。
下面是我用来绘制上面的图形的代码
这里是包含13条axhline()行的开始和结束日期的数据
fig, temp = plt.subplots()
temp.plot(df_w.index, df_w['TA_F'], color = 'red', label = 'TEMP')
# set x-label
temp.set_xlabel('Date')
temp.tick_params('x', labelsize =24)
# set primary y label
temp.set_ylabel('Tempurature (C)')
temp.tick_params('y', colors = 'red', labelsize =24)
# set x-axis limits as the min and max of the series
temp.set_xlim(date2num([df_w.index.min(), df_w.index.max()]))
temp.xaxis.set_major_formatter(mdates.DateFormatter('%d-%m-%Y'))
temp.xaxis.set_major_locator(mdates.YearLocator(1, month=1, day=1))
temp.set_ylim(2,28)
season = temp.twinx()
season.set_ylabel('GPP 20th percent yearly max')
season.tick_params('y', colors = 'blue', labelsize =24)
season.scatter(df_d.index, SRO_20['GPP_MINCORRECTED_20th'], marker = '^',color = 'blue')
plt.show()
https://stackoverflow.com/questions/72701102
复制相似问题