Python实现插值

from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
import numpy as np

x =[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
y1=[0.1975, 0.1942, 0.1895, 0.1848, 0.1660, 0.1645, 0.1646, 0.1641, 0.1649, 0.1652, 0.1664, 0.1680, 0.1686]
y2=[0.7232, 0.7253, 0.7280, 0.7305, 0.7453, 0.7443, 0.7415, 0.7392, 0.7345, 0.7301, 0.7251, 0.7182, 0.7120]
y3=[0.0793, 0.0805, 0.0825, 0.0847, 0.0887, 0.0912, 0.0939, 0.0967, 0.1006, 0.1047, 0.1085, 0.1139, 0.1194]

#绘制0-14岁人口所占比例插值图
from scipy.interpolate import spline
plt.figure(figsize=(8,6))
x_new = np.linspace(min(x),max(x),100)
y_smooth = spline(x, y1, x_new)
plt.ylim((0.16, 0.20))
my_y_ticks = np.arange(0.16, 0.201,0.005)
plt.yticks(my_y_ticks)
plt.plot(x_new, y_smooth)
plt.xticks((1,2,3,4,5,6,7,8,9,10,11,12,13),('2006年','2007年','2008年','2009年','2010年','2011年','2012年','2013年',
                                   '2014年','2015年','2016年','2017年','2018年'))
def baifenbi(temp,position):
    return"%.1f"%(100*temp)+"%"
plt.gca().yaxis.set_major_formatter(FuncFormatter(baifenbi))
plt.xlabel('年份')
plt.ylabel('0-14岁人口占总人口比例')
plt.show()

#绘制15-64岁人口所占比例插值图
from scipy.interpolate import spline
plt.figure(figsize=(8,6))
x_new = np.linspace(min(x),max(x),100)
y_smooth = spline(x, y2, x_new)
plt.ylim((0.70, 0.76))
my_y_ticks = np.arange(0.70, 0.76,0.005)
plt.yticks(my_y_ticks)
plt.plot(x_new, y_smooth)
plt.xticks((1,2,3,4,5,6,7,8,9,10,11,12,13),('2006年','2007年','2008年','2009年','2010年','2011年','2012年','2013年',
                                   '2014年','2015年','2016年','2017年','2018年'))
def baifenbi(temp,position):
    return"%.1f"%(100*temp)+"%"
plt.gca().yaxis.set_major_formatter(FuncFormatter(baifenbi))
plt.xlabel('年份')
plt.ylabel('15-64岁人口占总人口比例')
plt.show()

#绘制65岁及以上人口所占比例插值图
from scipy.interpolate import spline
plt.figure(figsize=(8,6))
x_new = np.linspace(min(x),max(x),100)
y_smooth = spline(x, y3, x_new)
plt.ylim((0.07, 0.13))
my_y_ticks = np.arange(0.07, 0.130001,0.01)
plt.yticks(my_y_ticks)
plt.plot(x_new, y_smooth)
plt.xticks((1,2,3,4,5,6,7,8,9,10,11,12,13),('2006年','2007年','2008年','2009年','2010年','2011年','2012年','2013年',
                                   '2014年','2015年','2016年','2017年','2018年'))
def baifenbi(temp,position):
    return"%.1f"%(100*temp)+"%"
plt.gca().yaxis.set_major_formatter(FuncFormatter(baifenbi))
plt.xlabel('年份')
plt.ylabel('65岁及以上人口占总人口比例')
plt.show()

运行效果如下:
在这里插入图片描述在这里插入图片描述在这里插入图片描述欢迎加群:620139909
在这里插入图片描述

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
cressman差值,程序、说明及例子 程序代码如下: subroutine interp_cressman(lati,loni,data,nxi,nyi, !此处给定了nxi,nyi,nxo,nyo目的是给据网格上的i、j在主程序是方便计算经纬度的值,如经纬 * lato,lono,datao,nxo,nyo) !给定了 是否就不用再给出nxi,nyi,nxo,nyo呢?而只要给出待插值网格的循环次数呢? !datao 是插值格点数据 !自己改写主程序和子程序的时候,可以使fvcom的经纬变成一维的L,就不必给出nxo,nyo了 c**** interpolates fields to another grid as specified c**** by lat., lon. values. c**** uses a Cressman interpolation with a specified c**** search radius c**** uses output from lookup.f to determine search points parameter(pi=3.14159,num=500) real lati(nxi,nyi),loni(nxi,nyi) real lato(nxo,nyo),lono(nxo,nyo) real data(nxi,nyi) integer ilon(num),ilat(num) real datao(nxo,nyo) open(30,file='lookup.tab1',status='unknown') open(31,file='lookup.tab2',status='unknown') guess = 100. ! search radius xmiss = -999. scale = 1. c************************************************************ c reinterpolate to NMC Octagonal grid using Cressman (应用cressman方法,逐步订正到NMC网格上) c weights with a specified search radius do 100 jj=1,nyo do 100 ii=1,nxo sum1=0. sum2=0. ilevs=0 c read in indices from lookup table read(30,*) ilevs c process indices if(ilevs.ne.0.)then read(31,*) (ilon(i),i=1,ilevs),(ilat(i),i=1,ilevs) !ilon,ilat没有定义? 有定义 do 90 kk=1,ilevs i = ilon(kk) j = ilat(kk) c find distance between NMC point to be interpolated to c and original point. dim=(sin(pi*lati(i,j)/180.)*sin(pi*lato(ii,jj)/180.)) dam=(cos(pi*lati(i,j)/180.)*cos(pi*lato(ii,jj)/180.)) dam1=lono(ii,jj)-loni(i,j) dam1=cos(pi*dam1/180.) dist=dim+dam*dam1 dist=acos(dist)*110.949*(180./pi) c dim=(sin(lati(i,j))*sin(lato(ii,jj))) c dam=(cos(l

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值