码迷,mamicode.com
首页 > 其他好文 > 详细

Intermezzo: A Data Analysis Session

时间:2014-11-06 12:22:03      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   sp   div   on   

# -*- coding: utf-8 -*-
"""
Created on Wed Nov 05 15:18:17 2014

@author: dell
"""

import pandas as pd
import numpy as np
import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

if __name__ == __main__:
    df = pd.read_table(carbon.dioxide.txt, header = None)
    data = np.array(list(df[0].values))
    
    fig = plt.figure()
    ax = fig.add_subplot(331)
    ax.plot(data)
    
    x = np.linspace(1, len(data), len(data))
    ax1 = fig.add_subplot(332)
    ax1.plot(data-315)
    ax1.plot(((x/350)**2)*35,--)
    
    ax3 = fig.add_subplot(333)
    ax3.plot(data-315)
    ax3.plot(((x/350)**1.35)*35, --)
    
    ax4 = fig.add_subplot(334)
    myres = data-315-((x/350)**1.35)*35
    ax4.plot(myres)

    ax1 = fig.add_subplot(335)
    from scipy.interpolate import UnivariateSpline
    #xs = np.linspace(1, len(data), len(data)*100)
    xs = np.linspace(1, len(data), 1000)
    s = UnivariateSpline(x, myres)
    ys = s(xs)
    ax1.plot(xs, ys)
    ax1.plot(myres)
    
    ax2 = fig.add_subplot(336)
    ax2.plot(myres)
    ax2.plot(3*np.sin(2*np.pi*x/12))
    
    ax3 = fig.add_subplot(337)
    myres1 = myres - 3*np.sin(2*np.pi*x/12) 
    #myres2 = data - 315-35*(x/350)**1.35 - 3*np.sin(np.pi*2*x/12)
    s1 = UnivariateSpline(x, myres1, s = 850)
    ys1 = s1(xs)
    ax3.plot(xs, ys1)
    ax3.plot(myres1)
    ax3.axhline(y = 1, ls = --)
    ax3.axhline(y = -1, ls = :)
    
    ax8 = fig.add_subplot(338)
    myfun = 315 + (x/350)**1.35*35 + 3*np.sin(2*np.pi*x/12) + 0.75*np.sin(2*np.pi*x/6) + 0.1
    ax8.plot(myfun, ls=:)
    ax8.plot(data)
    
    ax9 = fig.add_subplot(339)
    x = np.linspace(1, 800, 800)
    myfun = 315 + (x/350)**1.35*35 + 3*np.sin(2*np.pi*x/12) + 0.75*np.sin(2*np.pi*x/6) + 0.1
    ax9.plot(myfun, ls=:)
    ax9.plot(data)
    ax9.set_xlim(1, 800)
    
    plt.show()

bubuko.com,布布扣

http://files.cnblogs.com/hluo/carbon.dioxide.rar 

样条平滑函数还没有弄明白回事。

Intermezzo: A Data Analysis Session

标签:style   blog   http   io   color   ar   sp   div   on   

原文地址:http://www.cnblogs.com/hluo/p/4078185.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!