2017-11-13 4 views
0

私はドットと緑の線がforループのために動くようにこれをアニメーション化しようとしています。このコードは、3つの異なるグラフを上下に表示します。中間のグラフにはアニメーションセクションがありません。このグラフをアニメーションして、ドットが動くようにし、ループ内の各要素の緑色の線が異なる範囲にプロットするようにするにはどうすればよいですか?

x =lag_range 
count = 0 
plt.ion() 
fig, ax = plt.subplots() 
for b in x: 

    plt.subplot(311) 
    plt.plot(x,pear_corr, color='b', linewidth=1.5, label ='Pearson') 
    plt.plot(x,spear_corr, color ='r', linewidth=1.5, label='Spearman') 
    plt.plot(x[count],pear_corr[count],'yo') 
    plt.legend()  
    axes = plt.gca() 
    plt.ylabel('Correlation coefficients') 
    plt.xlabel('Lag times /days') 
    axes.set_xlim([min(lag_list),last]) 
    axes.set_ylim(-1,1) 

    plt.subplot(312) 
    plt.plot(x,pear_p_values, color='b', linewidth=1.5) 
    plt.plot(x,spear_p_values, color ='r', linewidth=1.5) 
    axes = plt.gca() 
    plt.ylabel('P values') 
    plt.xlabel('Lag times /days') 
    axes.set_xlim([min(lag_list),last]) 

    plt.subplot(313) 
    ax1 = plt.subplot(313) 
    x_for_p = range(len(x_prices)) 
    ax1.plot(x_for_p, x_prices, color ='grey', linewidth=1.5) 
    ax1.set_ylabel('Share price', color ='grey') 
    ax1.tick_params('y', colors='grey') 
    ax1.set_xlabel('Days') 
    axes = plt.gca() 
    axes.set_xlim([min(lag_list),(2*last)]) 

    ax2 = ax1.twinx() 
    x_for_den = range(b,(b+len(x_prices))) 
    ax2.plot(x_for_den, y_planes, color='g', linewidth=1.5) 
    ax2.set_ylabel('Plane density', color='g') 
    ax2.tick_params('y', colors='g') 

    count += 1 
    plt.pause(2) 
    plt.draw() 

cross_corr2_vis(価格、density_p3)

答えて

0

あなたが作業コードやその他の変数pear_corrspear_corr、のちょうど定義を共有することができれば、次のコードは、この単純なアニメーションでは得られていない可能性があります

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

N_points = 1000 

x = np.linspace(0,2.*np.pi,N_points) 
y = np.sin(x) 

fig, ax = plt.subplots() 
ax.set_xlim([0,2.*np.pi]) 
ax.set_ylim([-1,1]) 
line, = ax.plot( [],[], lw=2, color='g') 
sctr = ax.scatter([],[], s=100, color='r') 

def animate(i): 
    line.set_ydata(y[:i+1]) # update 
    line.set_xdata(x[:i+1]) 
    sctr.set_offsets((x[i],y[i])) 
    return line,sctr 

ani = animation.FuncAnimation(fig, animate, N_points, interval=5, blit=True) 
plt.show() 
関連する問題