Matplotlib:日期不一致格式的子图

时间:2018-03-21 03:56:02

标签: python pandas matplotlib formatting graphing

x轴刻度的格式在不同的子图之间不一致。我通过增加空间和格式化日期来尝试操作,但没有任何工作。日期列中的所有记录实际上都是日期。

fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(10,10), sharey='all')
plt.subplots_adjust(hspace = 0.3)
daily_performance[0].plot(x='date', y='return 1 day', kind='line', ax=ax[0,0])
daily_performance[1].plot(x='date', y='return 1 day', kind='line', ax=ax[0,1])
daily_performance[2].plot(x='date', y='return 1 day', kind='line', ax=ax[1,0])
daily_performance[3].plot(x='date', y='return 1 day', kind='line', ax=ax[1,1])
plt.show()

enter image description here

示例数据如下所示:

[        date  open        hi    lo   close  return 1 day  return 3 day  \
 0 2014-01-13  71.27  71.6000  69.49  70.12     -0.018340     -0.119869   
 1 2014-01-14  69.90  72.8200  69.58  72.67      0.036366     -0.013038   
 2 2014-01-15  72.74  73.4100  72.18  73.22      0.007568      0.025059   
 3 2014-01-16  73.16  73.4975  72.23  73.10     -0.001639      0.042499   
 4 2014-01-17  73.34  75.4500  73.06  75.42      0.031737      0.037842   

    return 5 day  
 0     -0.115986  
 1     -0.092306  
 2     -0.080959  
 3     -0.007198  
 4      0.055859  ,
         date   open        hi    lo    close  return 1 day  return 3 day  \
 5 2016-02-08  104.67  105.750  98.15  100.44     -0.045066     -0.097817   
 6 2016-02-09   99.70  101.160  94.01   96.28     -0.041418     -0.123293   
 7 2016-02-10   97.06   99.495  96.15   96.91      0.006543     -0.078627   
 8 2016-02-11   95.00   96.570  93.45   94.71     -0.022701     -0.057049   
 9 2016-02-12   95.51   99.040  94.36   98.63      0.041390      0.024408   

    return 5 day  
 5     -0.167302  
 6     -0.164164  
 7     -0.129525  
 8     -0.137589  
 9     -0.062274  ,
          date   open        hi     lo    close  return 1 day  return 3 day  \
 10 2016-02-09   99.70  101.160   94.01   96.28     -0.041418     -0.123293   
 11 2016-02-10   97.06   99.495   96.15   96.91      0.006543     -0.078627   
 12 2016-02-11   95.00   96.570   93.45   94.71     -0.022701     -0.057049   
 13 2016-02-12   95.51   99.040   94.36   98.63      0.041390      0.024408   
 14 2016-02-16  100.10  105.480  100.00  104.15      0.055967      0.074708   

     return 5 day  
 10     -0.164164  
 11     -0.129525  
 12     -0.137589  
 13     -0.062274  
 14      0.036937  ,
          date   open        hi     lo    close  return 1 day  return 3 day  \
 15 2016-02-10   97.06   99.495   96.15   96.91      0.006543     -0.078627   
 16 2016-02-11   95.00   96.570   93.45   94.71     -0.022701     -0.057049   
 17 2016-02-12   95.51   99.040   94.36   98.63      0.041390      0.024408   
 18 2016-02-16  100.10  105.480  100.00  104.15      0.055967      0.074708   
 19 2016-02-17  105.31  107.570  103.32  105.37      0.011714      0.112554   

     return 5 day  
 15     -0.129525  
 16     -0.137589  
 17     -0.062274  
 18      0.036937  
 19      0.094412  ]

0 个答案:

没有答案