def smooth_curve(curve_data,N_smooth,exp_max=-1,shift_0=0,fix_first_nonzero=False,plotit=False,t='x for plot'):
"""
smoothens the curve data for plotting as good as possible while maintaining last and first value
curve data => np.array, 1D that should be smoothened out
N_smooth => number of points to smooth over (float)
exp_max => adjust exponential behavior for average (0='normal' moving average)
shift_0 => manually fix from where on smoothing is active, e.g. up till where no smootthing is applied
fix_first_nonzero => if set to true, then automatically determines shift_0 to be where the first nonzero entry is
plotit => plot results
t => x-cooordinate for plot
"""
a=curve_data
N=N_smooth
v=np.exp(np.linspace(exp_max, 0., N))
v=v/v.sum()
a_v=np.convolve(a,v,'same')
if fix_first_nonzero==True:
shift_0=np.nonzero(a != 0)[0][0]
for n in range(0,len(v)):
if n!=0:
v=np.exp(np.linspace(exp_max, 0., n))
v=v/v.sum()
a_v[n+shift_0]=np.convolve(a,v,'same')[n+shift_0]
a_v[len(a)-n-1]=np.convolve(a,v,'same')[len(a)-n-1]
else:
a_v[n+shift_0]=a[n+shift_0]
for i in range(0,n+shift_0):
a_v[i]=a[i]
a_v[len(a)-n-1]=a[len(a)-n-1]
if plotit:
try:
np.sin(t)
except:
t=np.linspace(0,len(curve_data),len(curve_data))
import pylab as plt
plt.plot(t,a,label='original data')
plt.plot(t,a_v,label='smoothened')
plt.legend(loc='best',fancybox=True)
plt.title('curve smoothing')
plt.show()
return a_v
python类legend()的实例源码
def plot_measurements_and_simulation_results(time_points, ydata, y_sim):
pl.subplot2grid((4, 2), (0, 0))
pl.plot(time_points, ydata[:,0], label = "measurements")
pl.plot(time_points, y_sim[:,0], label = "simulation")
pl.title("Measurement data compared to simulation results")
pl.xlabel("t")
pl.ylabel("X", rotation = 0, labelpad = 20)
pl.legend(loc = "lower left")
pl.subplot2grid((4, 2), (1, 0))
pl.plot(time_points, ydata[:,1], label = "measurements")
pl.plot(time_points, y_sim[:,1], label = "simulation")
pl.xlabel("t")
pl.ylabel("Y", rotation = 0, labelpad = 15)
pl.legend("lower right")
pl.subplot2grid((4, 2), (2, 0))
pl.plot(time_points, ydata[:,2], label = "measurements")
pl.plot(time_points, y_sim[:,2], label = "simulation")
pl.xlabel("t")
pl.ylabel(r"\phi", rotation = 0, labelpad = 15)
pl.legend("lower left")
pl.subplot2grid((4, 2), (3, 0))
pl.plot(time_points, ydata[:,3], label = "measurements")
pl.plot(time_points, y_sim[:,3], label = "simulation")
pl.xlabel("t")
pl.ylabel("v", rotation = 0, labelpad = 20)
pl.legend("upperleft")
pl.subplot2grid((4, 2), (0, 1), rowspan = 4)
pl.plot(ydata[:,0], ydata[:, 1], label = "measurements")
pl.plot(y_sim[:,0], y_sim[:,1], label = "estimations")
pl.title("Measured race track compared to simulated results")
pl.xlabel("X")
pl.ylabel("Y", rotation = 0, labelpad = 20)
pl.legend(loc = "upper left")
pl.show()
4(improved-14).py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 42
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t, self.n_A1, 'b--', label='A1: Time Constant = 1')
pl.plot(self.t, self.n_B1, 'g', label='B1: Time Constant = 2')
pl.plot(self.t, self.n_A2, 'k--', label='A2: Time Constant = 1')
pl.plot(self.t, self.n_B2, 'c', label='B2: Time Constant = 2')
pl.plot(self.t, self.n_A3, 'm--', label='A3: Time Constant = 1')
pl.plot(self.t, self.n_B3, 'y', label='B3: Time Constant = 2')
pl.title('Double Decay Probelm - Nuclei with Different Time Constans')
pl.xlim(0.0, 5.0)
pl.ylim(0.0, 100.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='upper right', shadow=True, fontsize='small')
4(improved-13).py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 39
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t, self.n_A, 'b--', label='Number of Nuclei A: Time Constant = 1')
pl.plot(self.t, self.n_B, 'g', label='Number of Nuclei B: Time Constant = 2')
pl.title('Double Decay Probelm - Nuclei with Different Time Constans')
pl.xlim(0.0, 5.0)
pl.ylim(0.0, 100.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='best', shadow=True)
4(improved-1).py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 37
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t, self.n_A, 'b--', label='Number of Nuclei A')
pl.plot(self.t, self.n_B, 'g', label='Number of Nuclei B')
pl.title('Double Decay Probelm-Situation 1')
pl.xlim(0.0, 5.0)
pl.ylim(0.0, 100.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='best', shadow=True)
4(improved-9).py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 33
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t, self.n_A, 'b--', label='Number of Nuclei A: Time Constant = 2')
pl.plot(self.t, self.n_B, 'g', label='Number of Nuclei B: Time Constant = 1')
pl.title('Double Decay Probelm - Nuclei with Different Time Constans')
pl.xlim(0.0, 5.0)
pl.ylim(0.0, 100.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='best', shadow=True)
4(improved-8).py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 38
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t, self.n_A, 'b--', label='Number of Nuclei A: Time Constant = 1')
pl.plot(self.t, self.n_B, 'g', label='Number of Nuclei B: Time Constant = 2')
pl.title('Double Decay Probelm - Nuclei with Different Time Constans')
pl.xlim(0.0, 5.0)
pl.ylim(0.0, 100.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='best', shadow=True)
4(improved-3).py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 47
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t, self.n_A, 'b', label='Number of Nuclei A')
pl.plot(self.t, self.n_B, 'g+', label='Number of Nuclei B')
pl.title('Double Decay Probelm-Situation 3')
pl.xlim(0.0, 5.0)
pl.ylim(25.0, 75.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='best', shadow=True)
4(improved-10) 2.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 31
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t, self.n_A, 'b--', label='Number of Nuclei A')
pl.plot(self.t, self.n_B, 'b', label='Number of Nuclei B')
pl.plot(self.t, self.n_A_true, 'g--', label='True Number of Nuclei A')
pl.plot(self.t, self.n_B_true, 'g', label='True Number of Nuclei B')
pl.title('Double Decay Probelm-Approximation Compared with True')
pl.xlim(0.0, 2.5)
pl.ylim(0.0, 100.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='best', shadow=True)
pl.grid(True)
4(improved-4).py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 44
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t, self.n_A1, 'b--', label='A1')
pl.plot(self.t, self.n_B1, 'g', label='B1')
pl.plot(self.t, self.n_A2, 'r--', label='A2')
pl.plot(self.t, self.n_B2, 'c', label='B2')
pl.plot(self.t, self.n_A3, 'm', label='A3')
pl.plot(self.t, self.n_B3, 'k+', label='B3')
pl.title('Double Decay Probelm-Three Situations')
pl.xlim(0.0, 5.0)
pl.ylim(0.0, 100.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc="best", shadow=True, fontsize='small')
4(improved-12).py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t, self.n_A, 'b--', label='Number of Nuclei A: Time Constant = 2')
pl.plot(self.t, self.n_B, 'g', label='Number of Nuclei B: Time Constant = 1')
pl.title('Double Decay Probelm - Nuclei with Different Time Constans')
pl.xlim(0.0, 5.0)
pl.ylim(0.0, 100.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='best', shadow=True)
4(improved-6).py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 28
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t, self.n_A, 'b--', label='Number of Nuclei A')
pl.plot(self.t, self.n_B, 'b', label='Number of Nuclei B')
pl.plot(self.t, self.n_A_true, 'g--', label='True Number of Nuclei A')
pl.plot(self.t, self.n_B_true, 'g', label='True Number of Nuclei B')
pl.title('Double Decay Probelm-Approximation Compared with True')
pl.xlim(0.0, 2.5)
pl.ylim(0.0, 100.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='best', shadow=True)
pl.grid(True)
4(improved-10) 1.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 29
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t, self.n_A, 'b--', label='Number of Nuclei A')
pl.plot(self.t, self.n_B, 'b', label='Number of Nuclei B')
pl.plot(self.t, self.n_A_true, 'g--', label='True Number of Nuclei A')
pl.plot(self.t, self.n_B_true, 'g', label='True Number of Nuclei B')
pl.title('Double Decay Probelm-Approximation Compared with True')
pl.xlim(0.0, 2.5)
pl.ylim(0.0, 100.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='best', shadow=True)
pl.grid(True)
4(improved-2).py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 36
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t, self.n_A, 'b--', label='Number of Nuclei A')
pl.plot(self.t, self.n_B, 'g', label='Number of Nuclei B')
pl.title('Double Decay Probelm-Situation 2')
pl.xlim(0.0, 5.0)
pl.ylim(10.0, 90.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='best', shadow=True)
8 code1.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 38
收藏 0
点赞 0
评论 0
def show(self):
pl.plot(self.t, self.theta, label = '$F_D =$' + str(self.F_D))
pl.xlim(0, 100)
pl.ylim(-4, 4)
pl.xlabel('time ($s$)')
pl.ylabel('$\\theta$ (radians)')
pl.legend()
# pl.text(32, 2, '$\\theta$ versus time $F_D =$' + str(self.F_D))
#pl.subplot(311)
#r1 = routes_to_chaos(amplitude = 1.35)
#r1.calculate()
#r1.show()
#pl.subplot(312)
#r2 = routes_to_chaos(amplitude = 1.44)
#r2.calculate()
#r2.show()
#pl.subplot(313)
#r3 = routes_to_chaos(amplitude = 1.465)
#r3.calculate()
#r3.show()
#pl.show()
#r= routes_to_chaos(amplitude = 1.465)
#r.calculate()
#r.show()
def DrawTs(pl, ts=[], lines = None, title="", high=[], low=[],mid=[], save_file=False,legends=None):
"""?????, ts: closes, save_file: ?????????"""
pl.figure
legend = []
if len(ts)>0:
pl.plot(ts)
legend.append('ts')
if len(high)>0:
pl.plot(high)
legend.append('high')
if len(low)>0:
pl.plot(low)
legend.append('low')
if len(mid)>0:
pl.plot(mid)
legend.append('mid')
prop = fm.FontProperties(fname="c:/windows/fonts/simsun.ttc")
if title != "":
pl.title(title, fontproperties=prop)
if lines != None:
i = lines
if i>=len(ts):
i = len(ts)-1
pl.plot([i,i], [ts[i]-ts[i]*0.1, ts[i]+ts[i]*0.1], 'g')
legend.append('lines')
if legends is not None:
legend = legends
pl.legend(legend, loc='upper left')
if save_file:
fname = 't3.png'
pl.savefig(fname)
return fname
pl.show()
pl.close()
def DrawClosesAndVolumes(pl, closes, volumes, zz=None, avg=None, trade_index=None,\
title=None, closes_dp=None, closes_bankuai=None):
"""?closes??df???
closes_dp: ??
closes_bankuai: ??
"""
legend = []
pl.figure
pl.subplot(211)
if title != None:
pl.title(title, fontproperties=getFont())
pl.plot(closes)
legend.append('close')
if zz != None:
DrawZZ(pl, zz, c='r')
if avg != None:
pl.plot(avg)
if not agl.IsNone(closes_dp):
pl.plot(closes_dp)
legend.append('dapan')
if not agl.IsNone(closes_bankuai):
pl.plot(closes_bankuai)
legend.append('bankuai')
if trade_index != None:
pl, index, ts = pl, trade_index, closes
_DrawVLine(pl, index, ts)
pl.legend(legend, loc='upper left')
pl.subplot(212)
pl.plot(volumes)
pl.show()
pl.close()
def legend(self, *args, **kwargs):
pl.legend(*args, **kwargs)
def plot_checked(self):
import pylab as pl
pl.ioff()
from statistics import expectation
exp = []
# The expectation plotter
if len(self._stored_t) != 0:
pl.figure(2)
pl.title(" Method %s"%("OFSP"))
pl.xlabel("Time, t")
pl.ylabel("Expectation")
for i in range(len(self._stored_t)):
exp.append(expectation((self._stored_domain_states[i],self._stored_p[i])))
EXP = np.array(exp).T
for i in range(EXP.shape[0]):
pl.plot(self._stored_t,EXP[i,:],'x-',label=self.model.species[i])
pl.legend()
# The probability plotter
if len(self._probed_t) != 0:
pl.figure(3)
pl.title(" Method %s | Probing States over Time "%("OFSP"))
pl.xlabel("Time, t")
pl.ylabel("Probability")
probs = np.array(self._probed_probs).T
for i in range(probs.shape[0]):
pl.plot(self._probed_t,probs[i,:],'x-',label=str(self._probed_states[0][:,i]))
pl.legend()
pl.show()
def plot_checked(self):
"""
plot_checked plots the expectations of the data check pointed.
"""
import pylab as pl
pl.ioff()
if len(self._stored_t) != 0:
pl.figure(2)
pl.title(" Method %s"%(self.model_name))
pl.xlabel("Time,t")
pl.ylabel("Expectation")
exp = []
for i in range(len(self._stored_t)):
exp.append(np.sum(np.multiply(self._stored_X[i],self._stored_w[i]),axis=1))
EXP = np.array(exp).T
for i in range(EXP.shape[0]):
pl.plot(self._stored_t,EXP[i,:],'x-',label=self.model.species[i])
pl.legend()
# The probability plotter
if len(self._probed_t) != 0:
pl.figure(3)
pl.title(" Method %s | Probing States over Time "%(self.model_name))
pl.xlabel("Time, t")
pl.ylabel("Marginal Probability")
probs = np.array(self._probed_probs).T
for i in range(probs.shape[0]):
pl.plot(self._probed_t,probs[i,:],'x-',label=str(self._probed_states[0][self.stoc_vector,i]))
pl.legend()
pl.show()