def visualize_front(u, t, window_width, savefig=False): """ Visualize u and the exact solution vs t, using a moving plot window and continuous drawing of the curves as they evolve in time. Makes it easy to plot very long time series. P is the approximate duration of one period. """ import scitools.std as st from scitools.MovingPlotWindow import MovingPlotWindow umin = 1.2 * u.min() umax = -umin plot_manager = MovingPlotWindow(window_width=window_width, dt=t[1] - t[0], yaxis=[umin, umax], mode='continuous drawing') for n in range(1, len(u)): if plot_manager.plot(n): s = plot_manager.first_index_in_plot st.plot(t[s:n + 1], u[s:n + 1], 'r-1', title='t=%6.3f' % t[n], axis=plot_manager.axis(), show=not savefig) # drop window if savefig if savefig: print 't=%g' % t[n] st.savefig('tmp_vib%04d.png' % n) plot_manager.update(n)
def visualize_front(u, t, I, w, savefig=False): """ Visualize u and the exact solution vs t, using a moving plot window and continuous drawing of the curves as they evolve in time. Makes it easy to plot very long time series. """ import scitools.std as st from scitools.MovingPlotWindow import MovingPlotWindow P = 2*pi/w # one period umin = -1.2*I; umax = -umin plot_manager = MovingPlotWindow( window_width=8*P, dt=t[1]-t[0], yaxis=[umin, umax], mode='continuous drawing') for n in range(1,len(u)): if plot_manager.plot(n): s = plot_manager.first_index_in_plot st.plot(t[s:n+1], u[s:n+1], 'r-1', t[s:n+1], I*cos(w*t)[s:n+1], 'b-1', title='t=%6.3f' % t[n], axis=plot_manager.axis(), show=not savefig) # drop window if savefig if savefig: st.savefig('tmp_vib%04d.png' % n) plot_manager.update(n)
def visualize_front(u, t, I, w, savefig=False): """ Visualize u and the exact solution vs t, using a moving plot window and continuous drawing of the curves as they evolve in time. Makes it easy to plot very long time series. """ import scitools.std as st from scitools.MovingPlotWindow import MovingPlotWindow P = 2 * pi / w # one period umin = 1.2 * u.min() umax = -umin plot_manager = MovingPlotWindow(window_width=8 * P, dt=t[1] - t[0], yaxis=[umin, umax], mode='continuous drawing') for n in range(1, len(u)): if plot_manager.plot(n): s = plot_manager.first_index_in_plot st.plot(t[s:n + 1], u[s:n + 1], 'r-1', t[s:n + 1], I * cos(w * t)[s:n + 1], 'b-1', title='t=%6.3f' % t[n], axis=plot_manager.axis(), show=not savefig) # drop window if savefig if savefig: filename = 'tmp_vib%04d.png' % n st.savefig(filename) print 'making plot file', filename, 'at t=%g' % t[n] plot_manager.update(n)
def visualize_front(u, t, window_width, savefig=False): """ Visualize u and the exact solution vs t, using a moving plot window and continuous drawing of the curves as they evolve in time. Makes it easy to plot very long time series. P is the approximate duration of one period. """ import scitools.std as st from scitools.MovingPlotWindow import MovingPlotWindow umin = 1.2*u.min(); umax = -umin plot_manager = MovingPlotWindow( window_width=window_width, tau=t[1]-t[0], yaxis=[umin, umax], mode='continuous drawing') for n in range(1,len(u)): if plot_manager.plot(n): s = plot_manager.first_index_in_plot st.plot(t[s:n+1], u[s:n+1], 'r-1', title='t=%6.3f' % t[n], axis=plot_manager.axis(), show=not savefig) # drop window if savefig if savefig: print 't=%g' % t[n] st.savefig('tmp_vib%04d.png' % n) plot_manager.update(n)
def visualize_front(u, t, I, w, savefig=False, skip_frames=1): """ Visualize u and the exact solution vs t, using a moving plot window and continuous drawing of the curves as they evolve in time. Makes it easy to plot very long time series. Plots are saved to files if savefig is True. Only each skip_frames-th plot is saved (e.g., if skip_frame=10, only each 10th plot is saved to file; this is convenient if plot files corresponding to different time steps are to be compared). """ import scitools.std as st from scitools.MovingPlotWindow import MovingPlotWindow from math import pi # Remove all old plot files tmp_*.png import glob, os for filename in glob.glob('tmp_*.png'): os.remove(filename) P = 2 * pi / w # one period umin = 1.2 * u.min() umax = -umin dt = t[1] - t[0] plot_manager = MovingPlotWindow(window_width=8 * P, dt=dt, yaxis=[umin, umax], mode='continuous drawing') frame_counter = 0 for n in range(1, len(u)): if plot_manager.plot(n): s = plot_manager.first_index_in_plot st.plot(t[s:n + 1], u[s:n + 1], 'r-1', t[s:n + 1], I * cos(w * t)[s:n + 1], 'b-1', title='t=%6.3f' % t[n], axis=plot_manager.axis(), show=not savefig) # drop window if savefig if savefig and n % skip_frames == 0: filename = 'tmp_%04d.png' % frame_counter st.savefig(filename) print 'making plot file', filename, 'at t=%g' % t[n] frame_counter += 1 plot_manager.update(n)
def visualize_front(u, t, I, w, savefig=False, skip_frames=1): """ Visualize u and the exact solution vs t, using a moving plot window and continuous drawing of the curves as they evolve in time. Makes it easy to plot very long time series. Plots are saved to files if savefig is True. Only each skip_frames-th plot is saved (e.g., if skip_frame=10, only each 10th plot is saved to file; this is convenient if plot files corresponding to different time steps are to be compared). """ import scitools.std as st from scitools.MovingPlotWindow import MovingPlotWindow from math import pi # Remove all old plot files tmp_*.png import glob, os for filename in glob.glob("tmp_*.png"): os.remove(filename) P = 2 * pi / w # one period umin = 1.2 * u.min() umax = -umin dt = t[1] - t[0] plot_manager = MovingPlotWindow(window_width=8 * P, dt=dt, yaxis=[umin, umax], mode="continuous drawing") frame_counter = 0 for n in range(1, len(u)): if plot_manager.plot(n): s = plot_manager.first_index_in_plot st.plot( t[s : n + 1], u[s : n + 1], "r-1", t[s : n + 1], I * cos(w * t)[s : n + 1], "b-1", title="t=%6.3f" % t[n], axis=plot_manager.axis(), show=not savefig, ) # drop window if savefig if savefig and n % skip_frames == 0: filename = "tmp_%04d.png" % frame_counter st.savefig(filename) print "making plot file", filename, "at t=%g" % t[n] frame_counter += 1 plot_manager.update(n)
def visualize_front(u, t, U, omega, savefig=False, skip_frames=1): """ Стороится зависимость приближенного и точного решений от t с использованием анимированного изображения и непрерывного отображения кривых, изменяющихся со временем. Графики сохраняются в файлы, если параметр savefig=True. Только каждый skip_frames-й график сохраняется (например, если skip_frame=10, только каждый десятый график сохраняется в файл; это удобно, если нужно сравнивать графики для различных моментов времени). """ import scitools.std as st from scitools.MovingPlotWindow import MovingPlotWindow from math import pi # Удаляем все старые графики tmp_*.png import glob, os for filename in glob.glob('tmp_*.png'): os.remove(filename) P = 2 * pi / omega # один период umin = 1.2 * u.min(); umax = -umin tau = t[1] - t[0] plot_manager = MovingPlotWindow( window_width=8 * P, tau=tau, yaxis=[umin, umax], mode='continuous drawing') frame_counter = 0 for n in range(1, len(u)): if plot_manager.plot(n): s = plot_manager.first_index_in_plot st.plot(t[s:n + 1], u[s:n + 1], 'r-1', t[s:n + 1], U * np.cos(omega * t)[s:n + 1], 'b-1', title='t=%6.3f' % t[n], axis=plot_manager.axis(), show=not savefig) # пропускаем окно, если savefig if savefig and n % skip_frames == 0: filename = 'tmp_%04d.png' % frame_counter st.savefig(filename) print u'Создаем графический файл', filename, 't=%g' % t[n] frame_counter += 1 plot_manager.update(n)