zoukankan      html  css  js  c++  java
  • matplotlib画折线图,并以时间作为横轴

    代码:

     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()

    结果如下图所示。

  • 相关阅读:
    元素的隐藏和显示
    dateformat-参数表
    HTTP缓存控制小结
    Shell 快捷键
    PHP中的cURL库
    选择排序法
    双系统重装windows后如何恢复ubuntu启动项
    dell 3420 独立显卡黄色感叹号不能用问题
    YUY数据转换为RGB数据,并进行灰度化处理显示
    ubuntu 15.04安装显卡驱动,出现登录界面闪烁得解决方案(dell 3420 )
  • 原文地址:https://www.cnblogs.com/sunshine8/p/8040220.html
Copyright © 2011-2022 走看看