Python可视化 | 温度、水深&CTRL向量空间分布图

2021-03-25 15:10:02 浏览数 (2)

?欢迎大家关注气象水文科研猫


1 Map T_CTRL

代码语言:javascript复制
import numpy as np
import scipy as sp
from matplotlib import pyplot as plt
import mpl_toolkits.basemap as bm
# Scipy's io module needed to load MATLAB data
from scipy import io
from matplotlib import rcParams
config={"font.family":'Times New Roman',"font.size":14,"mathtext.fontset":'stix'}
rcParams.update(config)
# Load data
data = sp.io.loadmat('F:/Rpython/lp30/data/OFAM_model_mean.mat')
lon = data['lon']
lat = data['lat']
T_CTRL = data['T_CTRL']
T_A1B = data['T_A1B']
U_CTRL = data['U_CTRL']
V_CTRL = data['V_CTRL']
llon, llat = np.meshgrid(lon, lat)
# Map T_CTRL
fig = plt.figure(figsize=(16,9))
ax = fig.add_subplot(111)
proj = bm.Basemap(projection='cyl', llcrnrlat=-50, llcrnrlon=145, urcrnrlat=-20, urcrnrlon=180, resolution='i')
proj.drawcoastlines()
proj.etopo(scale=0.2)
parallels = np.arange(-50.,-19.9,5.)
proj.drawparallels(parallels,labels=[True,False,False,False],linewidth=0.5,color='red',dashes=[1,4],size=14)
meridians = np.arange(145.,181.,5.)
proj.drawmeridians(meridians,labels=[False,False,False,True],linewidth=0.5,color='red',dashes=[1,4],size=14)
lonproj,latproj = proj(llon, llat)
c1=ax.contourf(lonproj,latproj,T_CTRL,levels=np.arange(8,30,1),cmap='gist_rainbow',extend='both')
b=plt.colorbar(c1,shrink=0.99,orientation='vertical',pad=0.02,aspect=30,extend='both')
# add solid contour lines
CS=plt.contour(lonproj,latproj,T_CTRL,levels=np.arange(8,30,1),linewidth='0.5',colors='k')
plt.savefig('F:/Rpython/lp30/plot13.1.png',dpi=600)
plt.show()

2 Map T_CTRL - added velocity vectors

代码语言:javascript复制
fig = plt.figure(figsize=(16,9))
ax = fig.add_subplot(111)
proj = bm.Basemap(projection='cyl', llcrnrlat=-50, llcrnrlon=145, urcrnrlat=-20, urcrnrlon=180, resolution='i')
proj.drawcoastlines()
proj.etopo(scale=0.2)
parallels = np.arange(-50.,-19.9,5.)
proj.drawparallels(parallels,labels=[True,False,False,False],linewidth=0.5,color='red',dashes=[1,4],size=14)
meridians = np.arange(145.,181.,5.)
proj.drawmeridians(meridians,labels=[False,False,False,True],linewidth=0.5,color='red',dashes=[1,4],size=14)
lonproj, latproj = proj(llon, llat)
c1=ax.contourf(lonproj,latproj,T_CTRL,levels=np.arange(8,30,1),cmap='gist_rainbow',extend='both')
b=plt.colorbar(c1,shrink=0.99,orientation='vertical',pad=0.02,aspect=30,extend='both')
d = 5 # Only plot every dth point in lat and lon
plt.quiver(lonproj[0:-1:d,0:-1:d], latproj[0:-1:d,0:-1:d], U_CTRL[0:-1:d,0:-1:d], V_CTRL[0:-1:d,0:-1:d], scale=10)
# Load bathymetry data
bathy = data['bathy']
# Bathymetric contours of interest (where to draw the contours)
isobars = [0,200,500,1000,1500,2000,2500,3000,3500,4000,5000]
plt.savefig('F:/Rpython/lp30/plot13.2.png',dpi=600)
plt.show()

3 Nice bathymetry map

代码语言:javascript复制
# Map T_CTRL
fig = plt.figure(figsize=(16,9))
ax = fig.add_subplot(111)
proj = bm.Basemap(projection='cyl', llcrnrlat=-50, llcrnrlon=145, urcrnrlat=-20, urcrnrlon=180, resolution='i')
proj.drawcoastlines()
proj.etopo(scale=0.2)
parallels = np.arange(-50.,-19.9,5.)
proj.drawparallels(parallels,labels=[True,False,False,False],linewidth=0.5,color='red',dashes=[1,4],size=14)
meridians = np.arange(145.,181.,5.)
proj.drawmeridians(meridians,labels=[False,False,False,True],linewidth=0.5,color='red',dashes=[1,4],size=14)
lonproj, latproj = proj(llon, llat)
# Load bathymetry data
bathy = data['bathy']
# Bathymetric contours of interest (where to draw the contours)
isobars = [0,200,500,1000,1500,2000,2500,3000,3500,4000,5000]
c1=ax.contourf(lonproj, latproj, bathy,levels=isobars,cmap=plt.cm.RdYlBu,extend='both')
b=plt.colorbar(c1,shrink=0.99,orientation='vertical',pad=0.02,aspect=30,extend='both')
b.set_ticks(isobars)
b.set_label('Depth [m]')
plt.savefig('F:/Rpython/lp30/plot13.3.png',dpi=600)
plt.show()

4 Temperature change and bathymetry

代码语言:javascript复制
plt.figure(figsize=(14,5))
plt.subplot(1,2,1)
proj = bm.Basemap(projection='cyl', llcrnrlat=-50, llcrnrlon=145, urcrnrlat=-20, urcrnrlon=180, resolution='i')
proj.drawcoastlines()
proj.etopo(scale=0.2)
parallels = np.arange(-50.,-19.9,5.)
proj.drawparallels(parallels,labels=[True,False,False,False],linewidth=0.5,color='red',dashes=[1,4],size=14)
meridians = np.arange(145.,181.,5.)
proj.drawmeridians(meridians,labels=[False,False,False,True],linewidth=0.5,color='red',dashes=[1,4],size=14)
lonproj, latproj = proj(llon, llat)
c1=plt.contourf(lonproj,latproj,T_A1B-T_CTRL,levels=np.arange(-3,3 0.5,0.5),cmap=plt.cm.RdBu_r,extend='both')
cbar=plt.colorbar(c1,shrink=0.88,orientation='vertical',pad=0.03,aspect=30,extend='both')
cbar.set_label(r'SST [$^circ$C]')
plt.subplot(1,2,2)
proj = bm.Basemap(projection='cyl', llcrnrlat=-50, llcrnrlon=145, urcrnrlat=-20, urcrnrlon=180, resolution='i')
proj.drawcoastlines()
proj.etopo(scale=0.2)
parallels = np.arange(-50.,-19.9,5.)
proj.drawparallels(parallels,labels=[True,False,False,False],linewidth=0.5,color='red',dashes=[1,4],size=14)
meridians = np.arange(145.,181.,5.)
proj.drawmeridians(meridians,labels=[False,False,False,True],linewidth=0.5,color='red',dashes=[1,4],size=14)
lonproj, latproj = proj(llon, llat)
# Load bathymetry data
bathy = data['bathy']
# Bathymetric contours of interest (where to draw the contours)
isobars = [0,200,500,1000,1500,2000,2500,3000,3500,4000,5000]
c1=plt.contourf(lonproj,latproj,bathy,levels=isobars,cmap=plt.cm.RdYlBu,extend='both')
cbar=plt.colorbar(c1,shrink=0.88,orientation='vertical',pad=0.02,aspect=30,extend='both')
cbar.set_ticks(isobars)
cbar.set_label('Depth [m]')
plt.savefig('F:/Rpython/lp30/plot13.4.png',dpi=600)
plt.show()

0 人点赞