2017-04-14 1 views
2

다음 그림과 같이 기준면 투영 위에 여러 등고선을 그립니다. enter image description here.지도 가장자리의 등고선이베이스 맵에 표시되지 않습니다.

완전히 그려지지 않은 등고선이 있습니다 (오리건, 워싱턴 및 캘리포니아에서 ). 같은 위도에서 3 개 모두를 잘라낸 선이있는 것처럼 보입니다. 이 문제를 해결하는 방법을 모르겠습니다. 보간 점의 수를 추가했지만 도움이되지 않았습니다. ll과 ur가 더 많은 지역을 포함하도록 변경했습니다. 도움이되지 않았습니다.

아래 코드는 (재현하지하지만 도움이 될 수 있습니다)입니다 :

def visualise_bigaus(mus, sigmas, corxys , output_type='pdf', **kwargs): 





    lllat = 24.396308 
    lllon = -124.848974 
    urlat = 49.384358 
    urlon = -66.885444 

    fig = plt.figure(figsize=(4, 2.5)) 
    ax = fig.add_subplot(111, axisbg='w', frame_on=False) 
    m = Basemap(llcrnrlat=lllat, 
    urcrnrlat=urlat, 
    llcrnrlon=lllon, 
    urcrnrlon=urlon, 
    resolution='i', projection='cyl') 

    m.drawmapboundary(fill_color = 'white') 
    #m.drawcoastlines(linewidth=0.2) 
    m.drawcountries(linewidth=0.2) 
    m.drawstates(linewidth=0.2, color='lightgray') 
    #m.fillcontinents(color='white', lake_color='#0000ff', zorder=2) 
    #m.drawrivers(color='#0000ff') 
    m.drawlsmask(land_color='gray',ocean_color="#b0c4de", lakes=True) 
    lllon, lllat = m(lllon, lllat) 
    urlon, urlat = m(urlon, urlat) 
    mlon, mlat = m(*(mus[:,1], mus[:,0])) 
    numcols, numrows = 1000, 1000 
    X = np.linspace(mlon.min(), urlon, numcols) 
    Y = np.linspace(lllat, urlat, numrows) 

    X, Y = np.meshgrid(X, Y) 
    m.scatter(mlon, mlat, s=0.2, c='red') 
    shp_info = m.readshapefile('./data/us_states_st99/st99_d00','states',drawbounds=True, zorder=0) 
    printed_names = [] 
    ax = plt.gca() 
    ax.xaxis.set_visible(False) 
    ax.yaxis.set_visible(False) 
    for spine in ax.spines.itervalues(): 
     spine.set_visible(False) 


    for k in xrange(mus.shape[0]): 
     #here x is longitude and y is latitude 
     #apply softplus to sigmas (to make them positive) 
     sigmax=np.log(1 + np.exp(sigmas[k][1])) 
     sigmay=np.log(1 + np.exp(sigmas[k][0])) 
     mux=mlon[k] 
     muy=mlat[k] 
     corxy = corxys[k] 
     #apply the soft sign 
     corxy = corxy/(1 + np.abs(corxy)) 
     #now given corxy find sigmaxy 
     sigmaxy = corxy * sigmax * sigmay 

     #corxy = 1.0/(1 + np.abs(sigmaxy)) 
     Z = mlab.bivariate_normal(X, Y, sigmax=sigmax, sigmay=sigmay, mux=mux, muy=muy, sigmaxy=sigmaxy) 

     #Z = maskoceans(X, Y, Z) 


     con = m.contour(X, Y, Z, levels=[0.02], linewidths=0.5, colors='darkorange', antialiased=True) 
     ''' 
     num_levels = len(con.collections) 
     if num_levels > 1: 
      for i in range(0, num_levels): 
       if i != (num_levels-1): 
        con.collections[i].set_visible(False) 
     ''' 
     contour_labels = False 
     if contour_labels: 
      plt.clabel(con, [con.levels[-1]], inline=True, fontsize=10) 

    ''' 
    world_shp_info = m.readshapefile('./data/CNTR_2014_10M_SH/Data/CNTR_RG_10M_2014','world',drawbounds=False, zorder=100) 
    for shapedict,state in zip(m.world_info, m.world): 
     if shapedict['CNTR_ID'] not in ['CA', 'MX']: continue 
     poly = MplPolygon(state,facecolor='gray',edgecolor='gray') 
     ax.add_patch(poly) 
    '''     
    if iter: 
     iter = str(iter).zfill(3) 
    else: 
     iter = '' 
    plt.tight_layout() 
    plt.savefig('./maps/video/gaus_' + iter + '.' + output_type, frameon=False, dpi=200) 

답변

2

문제는 전체 맵을 포함하지 meshgrid입니다. meshgrid에는 가우스 등고선을 그리려는 위치에 점이 없습니다.

x 방향의 meshgrid가 -1에서 시작되는 지점에서이 지점을 그릴 수 없도록이 동작을 재현하는 예는 다음과 같습니다.

import matplotlib.pyplot as plt 
import matplotlib.mlab as mlab 
import numpy as np 

fig, ax=plt.subplots() 
ax.plot([-2,2],[-2,-2], alpha=0) 
X,Y = np.meshgrid(np.linspace(-1,2),np.linspace(-2,2)) 
Z = mlab.bivariate_normal(X, Y, sigmax=1., sigmay=1., mux=0.1, muy=0.1, sigmaxy=0) 
con = ax.contour(X, Y, Z, levels=[Z.max()/3, Z.max()/2., Z.max()*0.8],colors='darkorange') 
plt.show() 

enter image description here

비슷한 문제가 질문의 코드에서 발생합니다.
Y 방향으로, 당신은이 솔루션은 물론 어딘가 포틀랜드 메쉬를 시작하지만,하지 않는 것
X = np.linspace(mlon.min(), urlon, numcols)

당신이 mlon.min()에서 시작하는 메쉬를 제한 X 방향의 전체지도, Y = np.linspace(lllat, urlat, numrows)를 사용하는 동안 바다, 즉 표시된지도의 가장자리.

관련 문제