2017-01-25 4 views
-1

私はPythonでmatplotlib.pyplotを使用しています。 y軸は「ランキング損失」と呼ばれる実際の値であり、x軸は反復回数(1000)です。次に、各反復でアルゴリズムの2ランの平均ランキング損失をプロットします。Pythonプロットの奇妙な太い線はありますか?

誰かがなぜこの奇妙な太い線の代わりにチャートを取得するのですか?あなたの線密度は、ラインが道に重なるように高いことが、おそらくここで何が起こっている

fig = plt.figure() 
    fig.suptitle('Batch-GD', fontsize=20) 
    plt.xlabel('Iteration', fontsize=18) 
    plt.ylabel('Avg ranking loss', fontsize=16) 
    plt.grid(True) 
    plt.xlim(0, iter) 
    plt.plot(avg_loss) 
    fig.savefig('GD_with_ini.jpg') 
    plt.show() 
+1

あなたは私達にあなたの実際のプロットコマンドを表示することができますか? – Suever

+0

@ suever私はy軸の範囲を適切に設定する必要があると思います。質問にコードを追加しました。 – user5996916

+0

あなたの質問を編集し、そこにコードを含めてください。 –

答えて

3

enter image description here

とコマンドで事前にどうもありがとうございました線自体の代わりに平らな面が表示されていることを確認します。

非常に高い周波数でプロットを振動させると、同様の動作が得られます。拡大表示すると、実際に線が表示されます。

enter image description here

プロットを再現するコード:

import matplotlib.pyplot as plt 
import numpy as np 
from mpl_toolkits.axes_grid1.inset_locator import inset_axes, mark_inset 

x = np.linspace(0,1000,num=10000) 
y = np.sin(x*100.)*x/5000.+np.exp(-x/60.)+np.sin(x/50.)*0.016 

plt.plot(x,y) 

###### show inset #### 
ax = plt.gca() 
axins = inset_axes(ax, 2,2, loc=1) 
axins.plot(x,y) 
axins.set_xlim(400, 410) 
axins.set_ylim(-0.1, 0.17) 
mark_inset(ax, axins, loc1=2, loc2=4, fc="none", ec="0.5") 

plt.show() 

次いで、この溶液をローリング平均のいくつかの種類を計算することができます。例えば:

def running_mean(x, N): 
    cumsum = np.cumsum(np.insert(x, 0, 0)) 
    return (cumsum[N:] - cumsum[:-N])/N 
N=300 
cumsum = running_mean(y, N) 
ax.plot(x[N//2:-N//2+1], cumsum, c="orange") 
axins.plot(x[N//2:-N//2+1], cumsum, c="orange") 

enter image description here

+0

私はもう一度プログラムを実行しました(上のあなたのコメントのコマンドを使用して)、振動を実現しました。このローリング平均をとることは完璧です。どうもありがとうございました。 – user5996916

関連する問題