0
横波の磁場と電場波に対する透過率と反射率の4つのサブプロット間の間隔を調整しようとしています。私は1つの図プロットに4つのプロットを追加しました。私の目標は、サブプロットのマージンを変更して、サブプロットが重複しないようにすることです。以下のコードを使用しましたサブプロットのフォーマットとスペースを改善しました
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()
このサブプロットでは、次のような悪いフォーマットがあります。私はサブプロットマージンをどのように変更するかわからないので、互いに重なるサブプロットは得られません。
自動調整のための 'plt.tight_layoutを()'を使用を使用して調整することができます。それ以外の場合は、 'plt.subpots_adjust(...)'を使用して、必要に応じてパラメータを指定します。プロットに含まれていないデータについては、関数の度数ではなく、放射体の角度を差し込む必要があります。 (関数自体が正しいかどうかは分かりませんが、通常よりもはるかに複雑なようです。) – ImportanceOfBeingErnest
@ImportanceOfBeingErnest私は 'plt.tight_layout()'を試みましたが、私は十分な補完を得られませんでした。私は 'plt.subplots_adjust(top = 1.5、bottom = 0.18、left = 1、right = 1、hspace = 0.4、 wspace = 0.7)'を試してみましたが、これはうまくいきましたが、正しい設定を見つけることは本当のチャレンジになり始めています – kevin
値は図形サイズの端数です。それらを1より大きくすることは理にかなっていません。左==右を選択することも意味をなさない。 '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