爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
楼主: xiuyuanyang

[经验总结] 利用Python画中国地图外加站点分布

  [复制链接]

新浪微博达人勋

发表于 2017-10-15 10:59:47 | 显示全部楼层
很好,学习了
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-10-19 06:32:09 | 显示全部楼层
谢谢楼主分享
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-10-25 17:47:12 | 显示全部楼层
{:5_213:}
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2017-11-11 10:45:54 | 显示全部楼层
谢谢楼主分享
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-11-11 11:55:13 | 显示全部楼层
给力,萌新表示受益匪浅
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2018-1-19 17:05:32 | 显示全部楼层
多谢楼主分享
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2018-1-23 16:03:03 | 显示全部楼层
全全很给力的一个贴,感谢楼主分享!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2018-3-5 10:37:26 | 显示全部楼层
你好,我用spyder画图时变量场总是被地图遮挡,无论先画哪个,contourf,scatter都是这样,然而contour却是正常的,能帮忙看下这是怎么回事吗?
  1. import pandas as pd
  2. import numpy as np
  3. from sklearn.metrics import classification_report
  4. from sklearn.metrics import confusion_matrix
  5. from sklearn.metrics import accuracy_score
  6. from sklearn.metrics import precision_score
  7. from sklearn.metrics import recall_score
  8. from sklearn.metrics import f1_score
  9. import  matplotlib.pyplot as plt
  10. from scipy.io import loadmat
  11. from matplotlib.patches import Polygon
  12. from scipy.interpolate import griddata
  13. from mpl_toolkits.basemap import Basemap
  14. from matplotlib.font_manager import FontProperties
  15. # read in data, drop nan columns and convert floats into integers
  16. def Readdata():
  17. #    file1='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\DiscreOutput(0430-0608).xlsx'
  18. #    data1=pd.read_excel(file1,header=None)
  19. #    file2='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\DiscreOutput(0610-0715).xlsx'
  20. #    data2=pd.read_excel(file2,header=None)
  21. #    file3='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\DiscreOutput(0716-0815).xlsx'
  22. #    data3=pd.read_excel(file3,header=None)
  23. #    file4='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\DiscreOutput(0816-0901).xlsx'
  24. #    data4=pd.read_excel(file4,header=None)
  25. #    file5='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\DiscreOutput(0902-0910).xlsx'
  26. #    data5=pd.read_excel(file5,header=None)
  27. #    data=[data1,data2,data3,data4,data5]
  28.     file1='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\Output62720.xlsx'
  29.     data1=pd.read_excel(file1,header=None)
  30.     file2='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\Output80520.xlsx'
  31.     data2=pd.read_excel(file2,header=None)
  32.     file3='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\Output91220.xlsx'
  33.     data3=pd.read_excel(file3,header=None)
  34. #    file1='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\OriginalResult\Output62720.xlsx'
  35. #    data1=pd.read_excel(file1,header=None)
  36. #    file2='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\OriginalResult\Output80520.xlsx'
  37. #    data2=pd.read_excel(file2,header=None)
  38. #    file3='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\OriginalResult\Output91220.xlsx'
  39. #    data3=pd.read_excel(file3,header=None)
  40.     data=[data1,data2,data3]
  41.     Output=pd.concat(data,ignore_index=True)
  42.     Output=Output.dropna(axis=1,how='all')
  43.     Output.rename(columns={1:'date',2:'site',3:'fcst',4:'obs'},inplace=True)
  44.     Output['fcst']=Output['fcst'].apply(np.round)
  45.     return Output

  46. # prepare forecast and observation data
  47. def confusion(Output):
  48.     y_true=Output['obs']
  49.     y_pred=Output['fcst']
  50.     y_true=y_true[y_pred!=0.0]
  51.     y_pred=y_pred[y_pred!=0.0]
  52.     labels=list(set(y_true))
  53.     conf_mat=confusion_matrix(y_true,y_pred,labels=labels)
  54.     result=classification_report(y_true,y_pred)
  55.     accuracy=accuracy_score(y_true,y_pred)
  56.     print "classification_report(left:labels):"
  57.     print result
  58.     print "Accuracy(left:labels):"
  59.     print accuracy   
  60.     return conf_mat,result,accuracy

  61. Output=Readdata()
  62. P=[]
  63. R=[]
  64. f1=[]
  65. Ar=[]
  66. for i in enumerate(set(Output['site'])):
  67.     y_true=Output[Output['site']==i[1]]['obs']
  68.     y_pred=Output[Output['site']==i[1]]['fcst']
  69.     y_true=y_true[y_pred!=0.0]
  70.     y_pred=y_pred[y_pred!=0.0]
  71.     labels=[1,2,3]
  72.     P.append(precision_score(y_true,y_pred,labels=labels,average=None))
  73.     R.append(recall_score(y_true,y_pred,labels=labels,average=None))
  74.     f1.append(f1_score(y_true,y_pred,labels=labels,average=None))
  75.     Ar.append(accuracy_score(y_true,y_pred))
  76. P=np.array(P)
  77. R=np.array(R)
  78. f1=np.array(f1)
  79. Ar=np.array(Ar)
  80. # Plot contour of result
  81. font=FontProperties(fname=r'c:\windows\fonts\simsun.ttc',size=14)
  82. lonlat=loadmat('C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone\lonlat.mat')
  83. station=loadmat('C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone\station.mat')
  84. grid_lon,grid_lat=np.meshgrid(np.arange(105,110.5,0.1),np.arange(28,32.5,0.1))
  85. lon_lat=np.transpose(np.array([station['station'][:,0],lonlat['lonlat'][:,0],lonlat['lonlat'][:,1]]))
  86. STN=pd.DataFrame(lon_lat,columns=list('abc'))
  87. lon_lat=lon_lat[STN.isin(set(Output['site']))['a'],1:3]
  88. fig=plt.figure()
  89. ax1=fig.add_axes([0.1,0.1,0.8,0.8])
  90. #    ax0=fig.add_axes([0.85,0.10,0.04,0.80])
  91. map=Basemap(projection='cyl',resolution='l',llcrnrlon=105,llcrnrlat=28,urcrnrlon=111,urcrnrlat=33)
  92. shapeinfo=map.readshapefile('F:\\2016\\Youth_Foundation\\CHN_adm_shp\\CHN_adm3','states',drawbounds=False)
  93. for info, shp in zip(map.states_info,map.states):
  94.     proid=info['NAME_1']
  95.     if proid=='Chongqing':
  96.         poly=Polygon(shp,facecolor='w',edgecolor='k',lw=0.5)
  97.         ax1.add_patch(poly)
  98. map.drawparallels(np.arange(28,33,2),color='k',labels=[1,0,0,0])
  99. map.drawmeridians(np.arange(105,110,2),color='k',labels=[0,0,0,1])  
  100. agency=griddata(lon_lat,P[:,1],(grid_lon,grid_lat),method='cubic')
  101. cf=map.scatter(grid_lon,grid_lat,agency)
复制代码


contour.png
contourf.png
scatter.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2018-4-5 21:36:40 | 显示全部楼层
谢谢楼主分享,正好需要读取站点数据
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2018-4-8 14:18:17 | 显示全部楼层
感谢楼主这么详细的分享
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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