2016-04-20 4 views
2

バックグラウンドデータとフィット線で半ログプロットを作成しようとすると、フィット線が完全に曇ったように見える。ログスケール線が塗りつぶされている、半円のように見える

import numpy as np 
import matplotlib.pyplot as plt 

k=0 

for i in np.arange(0,len(emceeredshifts),7): 
    zbin=emceeredshifts[i+1] 
    lowradius = radius[(redshift <= (zbin + halfwidth)) & (redshift >= (zbin - halfwidth)) & (radius > 1) & (radius<20) &(mass>10.5)].flatten() 
    lowmass = mass[(redshift <= (zbin + halfwidth)) & (redshift >= (zbin - halfwidth)) & (radius > 1) & (radius<20)&(mass>10.5)].flatten() 
    if len(lowradius)>0: 
     lowfit = np.polyfit(lowmass, lowradius, 1) 
     lowlin,lowinter=np.poly1d(lowfit) 
     lowbestfit = lowinter + lowlin * (lowmass) 
     plt.plot(lowmass, lowbestfit, color=rainbowcolors[k], label=str(zbin)) 
    plt.scatter(lowmass, lowradius, color=rainbowcolors[k], marker='.', alpha=.2, edgecolor='none') 
    k+=1 

plt.legend(loc='lower right') 

plt.title("Galaxy radius vs mass\nlinear mcmc mass predictions") 
plt.xlabel("Log $M_\odot$") 
plt.ylabel("Physical radius (kpc)") 
plt.ylim(2,15) 
plt.xlim(10.6,11.8) 

plt.yscale('log') 
plt.show() 

ここではバグの半ログ結果を示します。 Buggy log-scale matplotlib line plot

ログスケールを削除すると、次のようになります。 y軸が線形の場合、線は線のように見え、データはデータのように見えます。 Linear scale plot

何が問題になりますか?

答えて

3

これらの行をプロットするために使用された配列の内容を調べましたか?私は彼らがソートされていないと思うので、mplはポイント間を行き来しています。線形空間では、これは同じ行に沿って描くだけなので、見えませんが、ログ空間では曲線のために目立ちます。

私はこの最小限の例では、問題を示し思う:

import numpy as np 
import matplotlib.pyplot as plt 

x = np.random.rand(1000) 
y = x.copy() 

fig,(ax1,ax2,ax3) = plt.subplots(3,figsize=(7,7)) 
fig.subplots_adjust(hspace=0.3) 

ax1.plot(x,y) 
ax1.set_title('linear') 

ax2.plot(x,y) 
ax2.set_yscale('log') 
ax2.set_title('log, unsorted') 

ind=np.argsort(x) 
ax3.plot(x[ind],y[ind]) 
ax3.set_yscale('log') 
ax3.set_title('log, sorted') 

plt.show() 

enter image description here

関連する問題