代码之家  ›  专栏  ›  技术社区  ›  CaptainEddy

X轴上带有整数和日期的Matplotlib交互式子图

  •  0
  • CaptainEddy  · 技术社区  · 6 年前

    x y (x轴值)。

    日期保持不变,因此完全不准确。

    请注意,这只是我的程序的简化版本。我将重新排列底部显示屏上的日期以进入底部。

    整数和日期必须链接起来,因为在我的实际程序中,我将使用整数来计算时间序列中的天数。

    import matplotlib.pyplot as plt
    import seaborn as sns
    
    
    x=[1,5,7,4,6]
    y=[1,3,8,4,6]
    fulldate=['01/01/2018','02/01/2018','03/01/2018','04/01/2018','05/01/2018']
    
    with sns.axes_style("darkgrid"):
    
          ax1=plt.subplot2grid((6,1),(0,0),rowspan=3,colspan=1)
          ax2=plt.subplot2grid((6,1),(4,0),rowspan=1,colspan=1,sharex=ax1)
          ax2v = ax2.twiny()
    
    
          ax1.plot(x,y)
          ax2v.fill_between(fulldate,'Dates')
          for label in ax2v.xaxis.get_ticklabels():
              label.set_rotation(60)
    
    0 回复  |  直到 6 年前