Matplotlib:日期格式不一致的子地块

2024-06-06 18:15:59 发布

您现在位置:Python中文网/ 问答频道 /正文

不同子地块之间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  ]

Tags: loclosedatereturnplotperformancelineplt