- 积分
- 5966
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-9-11
- 最后登录
- 1970-1-1
|
发表于 2018-3-5 10:37:26
|
显示全部楼层
你好,我用spyder画图时变量场总是被地图遮挡,无论先画哪个,contourf,scatter都是这样,然而contour却是正常的,能帮忙看下这是怎么回事吗?- import pandas as pd
- import numpy as np
- from sklearn.metrics import classification_report
- from sklearn.metrics import confusion_matrix
- from sklearn.metrics import accuracy_score
- from sklearn.metrics import precision_score
- from sklearn.metrics import recall_score
- from sklearn.metrics import f1_score
- import matplotlib.pyplot as plt
- from scipy.io import loadmat
- from matplotlib.patches import Polygon
- from scipy.interpolate import griddata
- from mpl_toolkits.basemap import Basemap
- from matplotlib.font_manager import FontProperties
- # read in data, drop nan columns and convert floats into integers
- def Readdata():
- # file1='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\DiscreOutput(0430-0608).xlsx'
- # data1=pd.read_excel(file1,header=None)
- # file2='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\DiscreOutput(0610-0715).xlsx'
- # data2=pd.read_excel(file2,header=None)
- # file3='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\DiscreOutput(0716-0815).xlsx'
- # data3=pd.read_excel(file3,header=None)
- # file4='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\DiscreOutput(0816-0901).xlsx'
- # data4=pd.read_excel(file4,header=None)
- # file5='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\DiscreOutput(0902-0910).xlsx'
- # data5=pd.read_excel(file5,header=None)
- # data=[data1,data2,data3,data4,data5]
- file1='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\Output62720.xlsx'
- data1=pd.read_excel(file1,header=None)
- file2='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\Output80520.xlsx'
- data2=pd.read_excel(file2,header=None)
- file3='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\Output91220.xlsx'
- data3=pd.read_excel(file3,header=None)
- # file1='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\OriginalResult\Output62720.xlsx'
- # data1=pd.read_excel(file1,header=None)
- # file2='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\OriginalResult\Output80520.xlsx'
- # data2=pd.read_excel(file2,header=None)
- # file3='C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone_1214temp\OriginalResult\Output91220.xlsx'
- # data3=pd.read_excel(file3,header=None)
- data=[data1,data2,data3]
- Output=pd.concat(data,ignore_index=True)
- Output=Output.dropna(axis=1,how='all')
- Output.rename(columns={1:'date',2:'site',3:'fcst',4:'obs'},inplace=True)
- Output['fcst']=Output['fcst'].apply(np.round)
- return Output
- # prepare forecast and observation data
- def confusion(Output):
- y_true=Output['obs']
- y_pred=Output['fcst']
- y_true=y_true[y_pred!=0.0]
- y_pred=y_pred[y_pred!=0.0]
- labels=list(set(y_true))
- conf_mat=confusion_matrix(y_true,y_pred,labels=labels)
- result=classification_report(y_true,y_pred)
- accuracy=accuracy_score(y_true,y_pred)
- print "classification_report(left:labels):"
- print result
- print "Accuracy(left:labels):"
- print accuracy
- return conf_mat,result,accuracy
- Output=Readdata()
- P=[]
- R=[]
- f1=[]
- Ar=[]
- for i in enumerate(set(Output['site'])):
- y_true=Output[Output['site']==i[1]]['obs']
- y_pred=Output[Output['site']==i[1]]['fcst']
- y_true=y_true[y_pred!=0.0]
- y_pred=y_pred[y_pred!=0.0]
- labels=[1,2,3]
- P.append(precision_score(y_true,y_pred,labels=labels,average=None))
- R.append(recall_score(y_true,y_pred,labels=labels,average=None))
- f1.append(f1_score(y_true,y_pred,labels=labels,average=None))
- Ar.append(accuracy_score(y_true,y_pred))
- P=np.array(P)
- R=np.array(R)
- f1=np.array(f1)
- Ar=np.array(Ar)
- # Plot contour of result
- font=FontProperties(fname=r'c:\windows\fonts\simsun.ttc',size=14)
- lonlat=loadmat('C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone\lonlat.mat')
- station=loadmat('C:\Users\CQQXT\Documents\MATLAB\BP_forecast_onebyone\station.mat')
- grid_lon,grid_lat=np.meshgrid(np.arange(105,110.5,0.1),np.arange(28,32.5,0.1))
- lon_lat=np.transpose(np.array([station['station'][:,0],lonlat['lonlat'][:,0],lonlat['lonlat'][:,1]]))
- STN=pd.DataFrame(lon_lat,columns=list('abc'))
- lon_lat=lon_lat[STN.isin(set(Output['site']))['a'],1:3]
- fig=plt.figure()
- ax1=fig.add_axes([0.1,0.1,0.8,0.8])
- # ax0=fig.add_axes([0.85,0.10,0.04,0.80])
- map=Basemap(projection='cyl',resolution='l',llcrnrlon=105,llcrnrlat=28,urcrnrlon=111,urcrnrlat=33)
- shapeinfo=map.readshapefile('F:\\2016\\Youth_Foundation\\CHN_adm_shp\\CHN_adm3','states',drawbounds=False)
- for info, shp in zip(map.states_info,map.states):
- proid=info['NAME_1']
- if proid=='Chongqing':
- poly=Polygon(shp,facecolor='w',edgecolor='k',lw=0.5)
- ax1.add_patch(poly)
- map.drawparallels(np.arange(28,33,2),color='k',labels=[1,0,0,0])
- map.drawmeridians(np.arange(105,110,2),color='k',labels=[0,0,0,1])
- agency=griddata(lon_lat,P[:,1],(grid_lon,grid_lat),method='cubic')
- cf=map.scatter(grid_lon,grid_lat,agency)
复制代码
|
|