2017-12-18 3 views
0

트랜스 자기 및 전기장 파에 대해 투과율 및 반사율의 4 가지 서브 플로트 사이의 간격을 조정하려고합니다. 필자는 4 개의 그림을 1 개의 그림으로 추가했습니다. 내 목표는 서브 플로트 마진을 변경하여 서브 플로트가 겹치지 않도록하는 것입니다. 아래 코드를 사용했습니다.서브 플로트의 형식 및 공간 개선

import matplotlib.pyplot as plt 
import numpy as np 


"DEFINE FRESNEL EQUATIONS" 


"""Define reflection coefficient for Transverse electric waves""" 

### Reflection coefficient 

def Ref_1(theta): 

    n_1=1.33 

    r_TE_1 = np.cos(theta) - np.sqrt(n_1**2 - np.sin(theta)**2) 
    r_TE_1 = r_TE_1/(r_TE_1 + 2*np.sqrt(n_1**2 - np.sin(theta)**2)) 

    return r_TE_1 


### transmission coefficient 

def Trans_1(theta): 

    n_2=1.5 

    r_TE_2 = 2*np.cos(theta) 
    r_TE_2 = r_TE_2/(np.cos(theta) + np.sqrt(n_2**2 - np.sin(theta)**2)) 

    return r_TE_2 


"""Define reflection coefficient for Transverse magnetic waves""" 


### Reflection coefficient 

def Ref_2(theta): 

    n_1=1.33 

    r_TM = np.sqrt(n_1**2 - np.sin(theta)**2) - n_1**2*np.cos(theta) 
    r_TM = r_TM/(np.sqrt(n_1**2 - np.sin(theta)**2) + n_1**2*np.cos(theta)) 

    return r_TM 


### transmission coefficient 

def Trans_2(theta): 

    n_2=1.5 

    r_TM_2 = 2*np.cos(theta) 
    r_TM_2 = r_TM_2/(np.cos(theta)*n_2**2+np.sqrt(n_2**2-np.sqrt(theta))**2) 

    return r_TM_2 


"Set Fontlabel, Fontaxis" 
Fontlabel=12 
Fontaxis=13 

"Plot results" 
plt.figure() 
fig=plt.figure() 

Hoek = np.linspace(0,90,1) 
print(Trans_2(100*(180/np.pi))) 
ax1=fig.add_subplot(221) 
ax1.plot(Hoek,Ref_1(Hoek),'blue',linewidth=0.8) 
plt.title('TE gepolariseerd licht bij Refrectie') 
plt.xlabel('$Hoek (\Theta)$') 
plt.ylabel('$Amplitude$') 

ax2=fig.add_subplot(222) 
ax2.plot(Hoek,Trans_1(Hoek),'red',linewidth=0.8) 
plt.title('TE gepolariseerd licht bij Transmissie') 
plt.xlabel('$Hoek (\Theta)$') 
plt.ylabel('$Amplitude$') 

ax3=fig.add_subplot(223) 
ax3.plot(Hoek,Ref_2(Hoek),'green',linewidth=0.8) 
plt.title('TM gepolariseerd licht bij Reflectie') 
plt.xlabel('$Hoek (\Theta)$') 
plt.ylabel('$Amplitude$') 


ax4=fig.add_subplot(224) 
ax4.plot(Hoek,Trans_2(Hoek),'black',linewidth=0.8) 
plt.title('TM gepolariseerd licht bij Transmissie') 
plt.xlabel('$Hoek (\Theta)$') 
plt.ylabel('$Amplitude$') 
plt.subplots_adjust(hspace=0.9) 
#plt.show() 

이 하위 플롯에는 다음과 같은 잘못된 형식이 있습니다. 나는 서브 플로트 마진을 어떻게 바꿀 지 모르기 때문에 서로 중첩하는 서브 플로트를 얻지 못합니다.

enter image description here

+0

사용'plt.tight_layout을()'사용하여 조정할 수 있습니다. 그렇지 않으면'plt.subpots_adjust (...)'를 사용하여 필요에 따라 매개 변수를 지정하십시오. 플롯에 존재하지 않는 데이터에 관해서는 함수에 각도가 아닌 방사형으로 각도를 연결해야합니다. (함수 자체가 올바른지 확실하지 않은 경우 정상적으로 사용하는 것보다 훨씬 복잡해 보입니다.) – ImportanceOfBeingErnest

+0

@ImportanceOfBeingErnest'plt.tight_layout()'을 시도했지만 만족스러운 adjusments를 얻지 못했습니다. 나는'plt.subplots_adjust (top = 1.5, bottom = 0.18, left = 1, right = 1, hspace = 0.4, wspace = 0.7)'을 시도 했었지만이 작업이 제대로 된 구성을 찾는 것은 실제적인 도전이되기 시작했다 – kevin

+0

값은 그림 크기의 분수입니다. 그것들을 1보다 크게 만드는 것은 의미가 없습니다. 또한 left == right를 선택하는 것은 의미가 없습니다. 'plt.subplots_adjust (top = 0.9, bottom = 0.2, left = 0.2, right = 0.8, hspace = 0.5, wspace = 0.5)와 같은 것으로 시작하자. 또한 figure를 크게 만드는 것을 고려해라. fig = plt.figure (figsize = (8,6))'. – ImportanceOfBeingErnest

답변

0

줄거리 사이의 공간은 다음과 같은 코드를 자동 조정에 대한

plt.subplots_adjust(top=1.5,bottom=0.18, left=0.2, right=2, hspace=0.4, wspace=0.2) 
관련 문제