请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 8473|回复: 4

[讨论] python快速绘图

[复制链接]

新浪微博达人勋

发表于 2020-2-6 23:37:16 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
python快速绘图,使用Argo网格数据绘制印尼海区的表层,100米,500米与1000米的温盐空间分布
  1. import netCDF4 as nc
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. from mpl_toolkits.basemap import Basemap as mp

  5. indir = 'E:\\ocean_file\\BOA_Argo\\';
  6. data = nc.Dataset(indir+'BOA_Argo_annual.nc','r')

  7. for i in data.variables.keys():
  8.     print (i)

  9. print('--------------------------')

  10. lon = data.variables['lon'][:]
  11. lat = data.variables['lat'][:]
  12. pres = data.variables['pres'][:]
  13. time = data.variables['time'][:]
  14. salt = data.variables['salt'][:]
  15. temp = data.variables['temp'][:]

  16. lons = 110;lone = 140;lats = -15;late = 15;
  17. x1s = np.argwhere(lon[:]>=lons);x1s1 = int(x1s[0])
  18. x1e = np.argwhere(lon[:]>=lone);x1e1 = int(x1e[0])
  19. y1s = np.argwhere(lat[:]>=lats);y1s1 = int(y1s[0])
  20. y1e = np.argwhere(lat[:]>=late);y1e1 = int(y1e[0])

  21. lon_IS = lon[x1s1:x1e1];lat_IS = lat[y1s1:y1e1]
  22. temp_IS = temp[0,:,y1s1:y1e1,x1s1:x1e1]
  23. salt_IS = salt[0,:,y1s1:y1e1,x1s1:x1e1]


  24. plt.figure(figsize=(10, 12))
  25. plt.subplot(221)
  26. m = mp(llcrnrlon=110., llcrnrlat=-15, urcrnrlon=140, urcrnrlat=15, resolution='c', projection='mill')
  27. m.drawcoastlines()
  28. m.drawparallels(np.arange(-90, 90, 10),labels=[1, 0, 0, 0])
  29. m.drawmeridians(np.arange(m.lonmin, m.lonmax+30, 10), labels=[0, 0, 0, 1])
  30. cmap = plt.cm.get_cmap('RdYlBu_r')
  31. levels = np.arange(32.8,34.5,0.1)
  32. x,y = np.meshgrid(lon_IS,lat_IS);x,y = m(x,y)
  33. m.contourf(x,y,salt_IS[0,:,:],alpha=0.75,cmap=cmap, levels=levels)
  34. m.colorbar(label='psu', location='bottom', pad=0.3)
  35. C = plt.contour(x,y,salt_IS[0,:,:],8,color='black',linewidth=0.5)
  36. plt.clabel(C,inline=1,fontsize=10)
  37. plt.title('Argo_annual_salt_@0m',loc='left', fontsize=18)

  38. plt.subplot(222)
  39. m = mp(llcrnrlon=110., llcrnrlat=-15, urcrnrlon=140, urcrnrlat=15, resolution='c', projection='mill')
  40. m.drawcoastlines()
  41. m.drawparallels(np.arange(-90, 90, 10),labels=[1, 0, 0, 0])
  42. m.drawmeridians(np.arange(m.lonmin, m.lonmax+30, 10), labels=[0, 0, 0, 1])
  43. cmap = plt.cm.get_cmap('RdYlBu_r')
  44. levels = np.arange(34.3,35.2,0.1)
  45. x,y = np.meshgrid(lon_IS,lat_IS);x,y = m(x,y)
  46. m.contourf(x,y,salt_IS[11,:,:],alpha=0.75,cmap=cmap, levels=levels)
  47. m.colorbar(label='psu', location='bottom', pad=0.3)
  48. C = plt.contour(x,y,salt_IS[11,:,:],8,color='black',linewidth=0.5)
  49. plt.clabel(C,inline=1,fontsize=10)
  50. plt.title('Argo_annual_salt_@100m',loc='left', fontsize=18)

  51. plt.subplot(223)
  52. m = mp(llcrnrlon=110., llcrnrlat=-15, urcrnrlon=140, urcrnrlat=15, resolution='c', projection='mill')
  53. m.drawcoastlines()
  54. m.drawparallels(np.arange(-90, 90, 10),labels=[1, 0, 0, 0])
  55. m.drawmeridians(np.arange(m.lonmin, m.lonmax+30, 10), labels=[0, 0, 0, 1])
  56. cmap = plt.cm.get_cmap('RdYlBu_r')
  57. levels = np.arange(34.3,34.7,0.02)
  58. x,y = np.meshgrid(lon_IS,lat_IS);x,y = m(x,y)
  59. m.contourf(x,y,salt_IS[34,:,:],alpha=0.75,cmap=cmap, levels=levels)
  60. m.colorbar(label='psu', location='bottom', pad=0.3)
  61. C = plt.contour(x,y,salt_IS[34,:,:],8,color='black',linewidth=0.5)
  62. plt.clabel(C,inline=1,fontsize=10)
  63. plt.title('Argo_annual_salt_@500m',loc='left', fontsize=18)

  64. plt.subplot(224)
  65. m = mp(llcrnrlon=110., llcrnrlat=-15, urcrnrlon=140, urcrnrlat=15, resolution='c', projection='mill')
  66. m.drawcoastlines()
  67. m.drawparallels(np.arange(-90, 90, 10),labels=[1, 0, 0, 0])
  68. m.drawmeridians(np.arange(m.lonmin, m.lonmax+30, 10), labels=[0, 0, 0, 1])
  69. cmap = plt.cm.get_cmap('RdYlBu_r')
  70. levels = np.arange(34.5,34.65,0.01)
  71. x,y = np.meshgrid(lon_IS,lat_IS);x,y = m(x,y)
  72. m.contourf(x,y,salt_IS[44,:,:],alpha=0.75,cmap=cmap, levels=levels)
  73. m.colorbar(label='psu', location='bottom', pad=0.3)
  74. C = plt.contour(x,y,salt_IS[44,:,:],8,color='black',linewidth=0.5)
  75. plt.clabel(C,inline=1,fontsize=10)
  76. plt.title('Argo_annual_salt_@1000m',loc='left', fontsize=18)

  77. plt.savefig('IS_salt.png',dpi=520)
复制代码


IS_salt1.png
IS_temp1.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2020-2-7 08:26:30 | 显示全部楼层
可以可以!!!
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2020-2-8 12:10:28 | 显示全部楼层
数据能否也发布一下呢
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2020-2-9 11:58:10 | 显示全部楼层
sihaike 发表于 2020-2-8 12:10
数据能否也发布一下呢

Argo网格数据地址:[url=http://www.argo.org.cn/]
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2020-2-9 12:07:16 | 显示全部楼层
Argo网格数据地址:[url=http://www.argo.org.cn/]
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表