十年網(wǎng)站開(kāi)發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無(wú)憂售后,網(wǎng)站問(wèn)題一站解決
import turtle
成都創(chuàng)新互聯(lián)主要為客戶提供服務(wù)項(xiàng)目涵蓋了網(wǎng)頁(yè)視覺(jué)設(shè)計(jì)、VI標(biāo)志設(shè)計(jì)、全網(wǎng)整合營(yíng)銷推廣、網(wǎng)站程序開(kāi)發(fā)、HTML5響應(yīng)式重慶網(wǎng)站建設(shè)公司、成都手機(jī)網(wǎng)站制作、微商城、網(wǎng)站托管及成都網(wǎng)站維護(hù)、WEB系統(tǒng)開(kāi)發(fā)、域名注冊(cè)、國(guó)內(nèi)外服務(wù)器租用、視頻、平面設(shè)計(jì)、SEO優(yōu)化排名。設(shè)計(jì)、前端、后端三個(gè)建站步驟的完善服務(wù)體系。一人跟蹤測(cè)試的建站服務(wù)標(biāo)準(zhǔn)。已經(jīng)為成都混凝土泵車行業(yè)客戶提供了網(wǎng)站營(yíng)銷服務(wù)。
turtle.showturtle() #屏幕上顯示出來(lái)海龜繪圖,終端中會(huì)用到
turtle.penup() #抬起畫(huà)筆,此時(shí)畫(huà)筆的移動(dòng)不會(huì)留下痕跡
turtle.pendown() #放下畫(huà)筆,此時(shí)畫(huà)筆的移動(dòng)會(huì)留下痕跡
turtle.pensize(3) #筆粗為3
turtle.goto(-200,100) #將畫(huà)筆移動(dòng)到(-200,100)坐標(biāo)
turtle.color("red") #設(shè)定畫(huà)筆的顏色為紅色
turtle.circle(100) #以當(dāng)前畫(huà)筆所在點(diǎn)為圓最下端開(kāi)始畫(huà)半徑為100的圓
turtle.circle(100,steps=n) #繪制一個(gè)周長(zhǎng)為100,的n邊形
turtle.forward(200) #將畫(huà)筆前進(jìn)200
turtle.backward(100) #將比后退100
turtle.right(70) #將畫(huà)筆箭頭的方向向右移70度
turtle.left(90) #將畫(huà)筆箭頭的方向向左移90度
turtle.stamp() #復(fù)制當(dāng)前圖形
turtle.write("hello,小朋友",font=('宋體',20,"normal")) #添加括號(hào)里的字符,font設(shè)置字符字體,大小以及作用
turtle.reste() #重置
turtle.hideturtle() #將畫(huà)筆隱藏
turtle.done() #把所繪圖顯示出來(lái),不關(guān)閉繪圖軟件
給繪制的圖形填充顏色
turtle.begin_fill()
turtle.circle(100)
turtle.color("yellow")
turtle.end_fill()
1
2
3
4
例:畫(huà)出奧運(yùn)五環(huán)
import turtle
turtle.color("blue")
turtle.circle(100)
turtle.penup()
turtle.goto(-200,0)
turtle.pendown()
turtle.color("red")
turtle.circle(100)
turtle.penup()
turtle.goto(200,0)
turtle.color("yellow")
turtle.pendown()
turtle.circle(100)
turtle.penup()
turtle.goto(-100,-100)
turtle.color("black")
turtle.pendown()
turtle.circle(100)
turtle.penup()
turtle.goto(100,-100)
turtle.color("black")
turtle.pendown()
turtle.circle(100)
turtle.done()
pre
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
def func(x):
return -(x-2)*(x-8)+40
x=np.linspace(0,10)
y=func(x)
fig,ax = plt.subplots()
plt.plot(x,y,'r',linewidth=2)
plt.ylim(ymin=20)
a=2
b=9
ax.set_xticks([a,b])
ax.set_xticklabels(['$a$','$b$'])
ax.set_yticks([])
plt.figtext(0.9,0.05,'$x$')
plt.figtext(0.1,0.9,'$y$')
ix=np.linspace(a,b)
iy=func(ix)
ixy=zip(ix,iy)
verts=[(a,0)]+list(ixy)+[(b,0)]
poly = Polygon(verts,facecolor='0.9',edgecolor='0.5')
ax.add_patch(poly)
x_math=(a+b)*0.5
y_math=35
plt.text(x_math,y_math,r"$\int_a^b(-(x-2)*(x-8)+40)dx$",horizontalalignment='center',size=12)
plt.show()
/pre
對(duì)于氣象繪圖來(lái)講,第一步是對(duì)數(shù)據(jù)的處理,通過(guò)各類公式,或者統(tǒng)計(jì)方法將原始數(shù)據(jù)處理為目標(biāo)數(shù)據(jù)。
按照氣象統(tǒng)計(jì)課程的內(nèi)容,我給出了一些常用到的統(tǒng)計(jì)方法的對(duì)應(yīng)函數(shù):
在計(jì)算氣候態(tài),區(qū)域平均時(shí)均要使用到求均值函數(shù),對(duì)應(yīng)NCL中的dim_average函數(shù),在python中通常使用np.mean()函數(shù)
numpy.mean(a, axis, dtype)
假設(shè)a為[time,lat,lon]的數(shù)據(jù),那么
需要特別注意的是,氣象數(shù)據(jù)中常有缺測(cè),在NCL中,使用求均值函數(shù)會(huì)自動(dòng)略過(guò),而在python中,當(dāng)任意一數(shù)與缺測(cè)(np.nan)計(jì)算的結(jié)果均為np.nan,比如求[1,2,3,4,np.nan]的平均值,結(jié)果為np.nan
因此,當(dāng)數(shù)據(jù)存在缺測(cè)數(shù)據(jù)時(shí),通常使用np.nanmean()函數(shù),用法同上,此時(shí)[1,2,3,4,np.nan]的平均值為(1+2+3+4)/4 = 2.5
同樣的,求某數(shù)組最大最小值時(shí)也有np.nanmax(), np.nanmin()函數(shù)來(lái)補(bǔ)充np.max(), np.min()的不足。
其他很多np的計(jì)算函數(shù)也可以通過(guò)在前邊加‘nan’來(lái)使用。
另外,
也可以直接將a中缺失值全部填充為0。
np.std(a, axis, dtype)
用法同np.mean()
在NCL中有直接求數(shù)據(jù)標(biāo)準(zhǔn)化的函數(shù)dim_standardize()
其實(shí)也就是一行的事,根據(jù)需要指定維度即可。
皮爾遜相關(guān)系數(shù):
相關(guān)可以說(shuō)是氣象科研中最常用的方法之一了,numpy函數(shù)中的np.corrcoef(x, y)就可以實(shí)現(xiàn)相關(guān)計(jì)算。但是在這里我推薦scipy.stats中的函數(shù)來(lái)計(jì)算相關(guān)系數(shù):
這個(gè)函數(shù)缺點(diǎn)和有點(diǎn)都很明顯,優(yōu)點(diǎn)是可以直接返回相關(guān)系數(shù)R及其P值,這避免了我們進(jìn)一步計(jì)算置信度。而缺點(diǎn)則是該函數(shù)只支持兩個(gè)一維數(shù)組的計(jì)算,也就是說(shuō)當(dāng)我們需要計(jì)算一個(gè)場(chǎng)和一個(gè)序列的相關(guān)時(shí),我們需要循環(huán)來(lái)實(shí)現(xiàn)。
其中a[time,lat,lon],b[time]
(NCL中為regcoef()函數(shù))
同樣推薦Scipy庫(kù)中的stats.linregress(x,y)函數(shù):
slop: 回歸斜率
intercept:回歸截距
r_value: 相關(guān)系數(shù)
p_value: P值
std_err: 估計(jì)標(biāo)準(zhǔn)誤差
直接可以輸出P值,同樣省去了做置信度檢驗(yàn)的過(guò)程,遺憾的是仍需同相關(guān)系數(shù)一樣循環(huán)計(jì)算。