代码:

 1 #!usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 import os
 4 import numpy as np
 5 import pandas as pd
 6 import matplotlib.pyplot as plt
 7 from datetime import datetime
 8 import matplotlib.dates as mdates
 9 from dateutil import parser
10 
11 base_dir = 'd:/Pattern/'
12 input_base_dir = base_dir + 'data_graph_save/'
13 
14 fileName = input_base_dir + 'output_6.csv'
15 data = pd.read_csv(fileName)
16 data_date_str = data.iloc[:, 0]
17 data_date = list(map(parser.parse, data_date_str))
18 data_cma = data.iloc[:, 1]
19 data_ecmwf = data.iloc[:, 2]
20 data_jma = data.iloc[:, 3]
21 data_ncep = data.iloc[:, 4]
22 data_mean = data.iloc[:, 5]
23 data_true = data.iloc[:, 6]
24 data_predict = data.iloc[:, 7]
25 
26 plt.figure(figsize=(13,7), dpi=80)
27 plt.subplot(1,1,1)
28 # 绘制余弦曲线,使用蓝色的、连续的、宽度为 1 (像素)的线条
29 plt.plot(data_date, data_predict, color='blue', linewidth=1.0, linestyle='-', label='predict')
30 plt.plot(data_date, data_true, color='red', linewidth=1.0, linestyle='-', label='observation')
31 plt.plot(data_date, data_cma, color='green', linewidth=1.0, linestyle='-', label='babj')
32 plt.plot(data_date, data_ecmwf, color='yellow', linewidth=1.0, linestyle='-', label='ecmf')
33 plt.plot(data_date, data_jma, color='purple', linewidth=1.0, linestyle='-', label='rjtd')
34 plt.plot(data_date, data_ncep, color='orange', linewidth=1.0, linestyle='-', label='kwbc')
35 plt.plot(data_date, data_mean, color='pink', linewidth=1.0, linestyle='-', label='mean')
36 # 显示图示
37 plt.legend()
38 
39 
40 # 配置横坐标
41 plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y'))
42 plt.gca().xaxis.set_major_locator(mdates.MonthLocator())    # 按月显示,按日显示的话,将MonthLocator()改成DayLocator()
43 plt.gcf().autofmt_xdate()  # 自动旋转日期标记
44 plt.title('Temperation constraction')
45 plt.savefig('temper.png')
46 plt.show()

结果如下图所示。