def show(self):
# pl.semilogy(self.theta, self.omega)
# , label = '$L =%.1f m, $'%self.l + '$dt = %.2f s, $'%self.dt + '$\\theta_0 = %.2f radians, $'%self.theta[0] + '$q = %i, $'%self.q + '$F_D = %.2f, $'%self.F_D + '$\\Omega_D = %.1f$'%self.Omega_D)
pl.plot(self.time_array,self.delta)
# pl.show()
# pl.semilogy(self.time_array, self.delta)
# pl.legend(loc = 'upper center', fontsize = 'small')
# pl.xlabel('$time (s)$')
# pl.ylabel('$\\Delta\\theta (radians)$')
# pl.xlim(0, self.T)
# pl.ylim(float(input('ylim-: ')),float(input('ylim+: ')))
# pl.ylim(1E-11, 0.01)
# pl.text(4, -0.15, 'nonlinear pendulum - Euler-Cromer method')
# pl.text(10, 1E-3, '$\\Delta\\theta versus time F_D = 0.5$')
# pl.title('Simple Harmonic Motion')
# pl.title('Chaotic Regime')
python类show()的实例源码
7 code.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
7 code.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def show_log(self):
# pl.subplot(121)
pl.semilogy(self.time_array, self.delta, 'c')
pl.xlabel('$time (s)$')
pl.ylabel('$\\Delta\\theta$ (radians)')
pl.xlim(0, self.T)
# pl.ylim(1E-11, 0.01)
pl.text(42, 1E-7, '$\\Delta\\theta$ versus time $F_D = 1.2$', fontsize = 'x-large')
pl.title('Chaotic Regime')
pl.show()
# def show_log_sub122(self):
# pl.subplot(122)
# pl.semilogy(self.time_array, self.delta, 'g')
# pl.xlabel('$time (s)$')
# pl.ylabel('$\\Delta\\theta$ (radians)')
# pl.xlim(0, self.T)
# pl.ylim(1E-6, 100)
# pl.text(20, 1E-5, '$\\Delta\\theta$ versus time $F_D = 1.2$', fontsize = 'x-large')
# pl.title('Chaotic Regime')
# pl.show()
6 code.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def show_complex(self):
font = {'family': 'serif',
'color': 'k',
'weight': 'normal',
'size': 16,
}
pl.title('The Trajectory of Tageted Baseball\n with air flow in adiabatic model', fontdict = font)
pl.plot(self.x, self.y, label = '$v_0 = %.5f m/s$'%self.v0 + ', ' + '$\\theta = %.4f \degree$'%self.theta)
pl.xlabel('x $m$')
pl.ylabel('y $m$')
pl.xlim(0, 300)
pl.ylim(-100, 20)
pl.grid()
pl.legend(loc = 'upper right', shadow = True, fontsize = 'small')
pl.text(15, -90, 'scan to approach the minimum velocity and corresponding launching angle', fontdict = font)
pl.show()
6 code.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def show_simple(self):
font = {'family': 'serif',
'color': 'k',
'weight': 'normal',
'size': 16,
}
pl.title('The Trajectory of Tageted Baseball\n with air flow in adiabatic model', fontdict = font)
pl.plot(self.x, self.y, label ='$\\alpha = %.0f \degree$'%self.alpha)
pl.xlabel('x $m$')
pl.ylabel('y $m$')
pl.xlim(0, 400)
pl.ylim(-100, 200)
pl.grid()
pl.legend(loc = 'upper right', shadow = True, fontsize = 'medium')
pl.text(5, -80, 'trojectories varing with angles of wind', fontdict = font)
pl.show()
6 code.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def double_scan(self):
v_0 = 81.09589
while 0 <= v_0:
theta_0 = 7.1610
while 7.1610 <= theta_0 < 7.1620:
t = targeted_baseball(v_0, theta_0, 0.01, 10, 135)
t.calculate()
t.show()
if a < 220:
theta_0 = theta_0 + 0.0001
else:
print(a, '\n', v_0,'\n', theta_0)
break
v_0 = v_0 + 0.00001
if a >= 220:
break
5 code 1.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def show_results(self):
font = {'family': 'serif',
'color': 'k',
'weight': 'normal',
'size': 14,
}
pl.plot(self.x, self.y, 'c', label='firing angle = 45°')
pl.title('The Trajectory of a Cannon Shell', fontdict = font)
pl.xlabel('x (k$m$)')
pl.ylabel('y ($km$)')
pl.xlim(0, 60)
pl.ylim(0, 20)
pl.grid(True)
pl.legend(loc='upper right', shadow=True, fontsize='large')
pl.text(41, 16, 'Only with air drag', fontdict = font)
pl.show()
5 code 2.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def show_results(self):
font = {'family': 'serif',
'color': 'k',
'weight': 'normal',
'size': 12,
}
pl.plot(self.x, self.y, 'c', label='firing angle = 45°')
pl.title('The Trajectory of a Cannon Shell', fontdict = font)
pl.xlabel('x (k$m$)')
pl.ylabel('y ($km$)')
pl.xlim(0, 60)
pl.ylim(0, 20)
pl.grid(True)
pl.legend(loc='upper right', shadow=True, fontsize='large')
pl.text(34, 16, ' With both air drag and \n reduced air density-isothermal', fontdict = font)
pl.show()
5 code 3.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def show_results(self):
font = {'family': 'serif',
'color': 'k',
'weight': 'normal',
'size': 12,
}
pl.plot(self.x, self.y, 'c', label='firing angle = 45°')
pl.title('The Trajectory of a Cannon Shell', fontdict = font)
pl.xlabel('x (k$m$)')
pl.ylabel('y ($km$)')
pl.xlim(0, 60)
pl.ylim(0, 20)
pl.grid(True)
pl.legend(loc='upper right', shadow=True, fontsize='large')
pl.text(34.5, 16, ' With both air drag and \n reduced air density-adiabatic', fontdict = font)
pl.show()
def DrawDvs(pl, closes, curve, sign, dvs, pandl, sh, title, leag=None, lad=None ):
pl.figure
pl.subplot(311)
pl.title("id:%s Sharpe ratio: %.2f"%(str(title),sh))
pl.plot(closes)
DrawLine(pl, sign, closes)
pl.subplot(312)
pl.grid()
if dvs != None:
pl.plot(dvs)
if isinstance(curve, np.ndarray):
DrawZZ(pl, curve, 'r')
if leag != None:
pl.plot(leag, 'r')
if lad != None:
pl.plot(lad, 'b')
#pl.plot(stock.GuiYiHua(closes[:i])[60:])
pl.subplot(313)
pl.plot(sign)
pl.plot(pandl)
pl.show()
pl.close()
def DrawDvsAndZZ(pl, dvs, zz, closes=None):
"""dvs?zz??????; dvs : ????closes, """
dvs = np.array(dvs)
pl.figure
if closes == None:
pl.plot(dvs)
pl.plot(zz[:,0], zz[:,1], 'r')
else:
pl.subplot(211)
pl.plot(closes)
pl.grid()
pl.subplot(212)
pl.grid()
pl.plot(dvs)
pl.plot(zz[:,0], zz[:,1], 'r')
pl.show()
pl.close()
def DrawHist(pl, shs):
"""??????, shs: ??? array"""
shs = np.array(shs, dtype=float)
#print "mean: %.2f"%shs.mean()
shs = shs[np.isnan(shs) == False]
if len(shs)>0:
pl.figure
pl.hist(shs)
def ShowHitCount(shs):
#????
go_count = len(shs) - len(shs[np.isnan(shs)])
#???
if len(shs) != 0:
v = float(go_count)/ float(len(shs))
#print("trade rato:%.2f%%"%(v*100))
#?????
if go_count>0:
v = float(len(shs[shs>0]))/float(go_count)
#print("win rato: %.2f%%"%(v*100))
pl.show()
#ShowHitCount(shs)
def _test_AsynDrawKline(self):
code = '300033'
start_day = '2017-8-25'
#df = stock.getHisdatDataFrameFromRedis(code, start_day)
df = stock.getFiveHisdatDf(code, start_day=start_day)
import account
account = account.LocalAcount(account.BackTesting())
#????????
indexs = agl.GenRandomArray(len(df), 3)
trade_bSell = [0,1,0]
df_trades = df[df.index.map(lambda x: x in df.index[indexs])]
df_trades = df_trades.copy()
df_trades[AsynDrawKline.enum.trade_bSell] = trade_bSell
plt.ion()
for i in range(10):
AsynDrawKline.drawKline(df[i*10:], df_trades)
plt.ioff()
#plt.show() #???????? ????????
def _test_boll(self):
code = '300113'
df_five_hisdat = getFiveHisdatDf(code,'2017-5-1')
#print(closes)
#upper, middle, lower = BOLL(df_five_hisdat['c'])
#print(upper[-1], lower[-1])
upper, middle, lower = TDX_BOLL(df_five_hisdat['c'])
print upper[-10:]
print middle[-10:]
print lower[-10:]
#df_five_hisdat['upper'] = upper
#df_five_hisdat['lower'] = lower
#df_five_hisdat['mid'] = middle
#df = df_five_hisdat[['upper', 'c', 'mid', 'lower']]
#df.plot()
#pl.show()
upper, middle, lower, boll_w = TDX_BOLL2(df_five_hisdat['c'])
print boll_w
def plot(self):
#??????????????????
pl.figure
#?????
a = []
for h in self.weituo_historys:
a.append(h.price)
a = GuiYiHua(a)
pl.plot(a, 'b')
#???
a = np.array(self.total_moneys)
a = GuiYiHua(a)
pl.plot(a, 'r')
pl.legend(['price list', 'money list'])
pl.show()
pl.close()
#???????????????, ??????????
def Unittest_Kline():
""""""
kline = Guider("600100", "")
print(kline.getData(0).date, kline.getLastData().date)
#kline.myprint()
obv = kline.OBV()
pl.figure
pl.subplot(2,1,1)
pl.plot(kline.getCloses())
pl.subplot(2,1,2)
ma,m2,m3 = kline.MACD()
pl.plot(ma)
pl.plot(m2,'r')
left = np.arange(0, len(m3))
pl.bar(left,m3)
#pl.plot(obv, 'y')
pl.show()
#Unittest_Kstp()
#
#???????????
#----------------------------------------------------------------------
def visualize_reconstruction(xp, model, x, visualization_dir, epoch, gpu=False):
x_variable = chainer.Variable(xp.asarray(x))
_x = model.decode(model.encode(x_variable), test=True)
_x.to_cpu()
_x = _x.data
fig = pylab.gcf()
fig.set_size_inches(8.0, 8.0)
pylab.clf()
pylab.gray()
for m in range(50):
i = m / 10
j = m % 10
pylab.subplot(10, 10, 20 * i + j + 1, xticks=[], yticks=[])
pylab.imshow(x[m].reshape((28, 28)), interpolation="none")
pylab.subplot(10, 10, 20 * i + j + 10 + 1, xticks=[], yticks=[])
pylab.imshow(_x[m].reshape((28, 28)), interpolation="none")
# pylab.imshow(np.clip((_x_batch.data[m] + 1.0) / 2.0, 0.0, 1.0).reshape(
# (config.img_channel, config.img_width, config.img_width)), interpolation="none")
pylab.axis("off")
pylab.savefig("{}/reconstruction_{}.png".format(visualization_dir, epoch))
# pylab.show()
def view_waveforms_clusters(data, halo, threshold, templates, amps_lim, n_curves=200, save=False):
nb_templates = templates.shape[1]
n_panels = numpy.ceil(numpy.sqrt(nb_templates))
mask = numpy.where(halo > -1)[0]
clust_idx = numpy.unique(halo[mask])
fig = pylab.figure()
square = True
center = len(data[0] - 1)//2
for count, i in enumerate(xrange(nb_templates)):
if square:
pylab.subplot(n_panels, n_panels, count + 1)
if (numpy.mod(count, n_panels) != 0):
pylab.setp(pylab.gca(), yticks=[])
if (count < n_panels*(n_panels - 1)):
pylab.setp(pylab.gca(), xticks=[])
subcurves = numpy.where(halo == clust_idx[count])[0]
for k in numpy.random.permutation(subcurves)[:n_curves]:
pylab.plot(data[k], '0.5')
pylab.plot(templates[:, count], 'r')
pylab.plot(amps_lim[count][0]*templates[:, count], 'b', alpha=0.5)
pylab.plot(amps_lim[count][1]*templates[:, count], 'b', alpha=0.5)
xmin, xmax = pylab.xlim()
pylab.plot([xmin, xmax], [-threshold, -threshold], 'k--')
pylab.plot([xmin, xmax], [threshold, threshold], 'k--')
#pylab.ylim(-1.5*threshold, 1.5*threshold)
ymin, ymax = pylab.ylim()
pylab.plot([center, center], [ymin, ymax], 'k--')
pylab.title('Cluster %d' %i)
if nb_templates > 0:
pylab.tight_layout()
if save:
pylab.savefig(os.path.join(save[0], 'waveforms_%s' %save[1]))
pylab.close()
else:
pylab.show()
del fig
def view_artefact(data, save=False):
fig = pylab.figure()
pylab.plot(data.T)
if save:
pylab.savefig(os.path.join(save[0], 'artefact_%s' %save[1]))
pylab.close()
else:
pylab.show()
del fig
def view_trigger_snippets(trigger_snippets, chans, save=None):
# Create output directory if necessary.
if os.path.exists(save):
for f in os.listdir(save):
p = os.path.join(save, f)
os.remove(p)
os.removedirs(save)
os.makedirs(save)
# Plot figures.
fig = pylab.figure()
for (c, chan) in enumerate(chans):
ax = fig.add_subplot(1, 1, 1)
for n in xrange(0, trigger_snippets.shape[2]):
y = trigger_snippets[:, c, n]
x = numpy.arange(- (y.size - 1) / 2, (y.size - 1) / 2 + 1)
b = 0.5 + 0.5 * numpy.random.rand()
ax.plot(x, y, color=(0.0, 0.0, b), linestyle='solid')
y = numpy.mean(trigger_snippets[:, c, :], axis=1)
x = numpy.arange(- (y.size - 1) / 2, (y.size - 1) / 2 + 1)
ax.plot(x, y, color=(1.0, 0.0, 0.0), linestyle='solid')
ax.grid(True)
ax.set_xlim([numpy.amin(x), numpy.amax(x)])
ax.set_title("Channel %d" %chan)
ax.set_xlabel("time")
ax.set_ylabel("amplitude")
if save is not None:
# Save plot.
filename = "channel-%d.png" %chan
path = os.path.join(save, filename)
pylab.savefig(path)
fig.clf()
if save is None:
pylab.show()
else:
pylab.close(fig)
return
def view_mahalanobis_distribution(data_1, data_2, save=None):
'''Plot Mahalanobis distribution Before and After'''
fig = pylab.figure()
ax = fig.add_subplot(1,2,1)
if len(data_1) == 3:
d_gt, d_ngt, d_noi = data_1
elif len(data_1) == 2:
d_gt, d_ngt = data_1
if len(data_1) == 3:
ax.hist(d_noi, bins=50, color='k', alpha=0.5, label="Noise")
ax.hist(d_ngt, bins=50, color='b', alpha=0.5, label="Non GT")
ax.hist(d_gt, bins=75, color='r', alpha=0.5, label="GT")
ax.grid(True)
ax.set_title("Before")
ax.set_ylabel("")
ax.set_xlabel('# Samples')
ax.set_xlabel('Distances')
if len(data_2) == 3:
d_gt, d_ngt, d_noi = data_2
elif len(data_2) == 2:
d_gt, d_ngt = data_2
ax = fig.add_subplot(1,2,2)
if len(data_2) == 3:
ax.hist(d_noi, bins=50, color='k', alpha=0.5, label="Noise")
ax.hist(d_ngt, bins=50, color='b', alpha=0.5, label="Non GT")
ax.hist(d_gt, bins=75, color='r', alpha=0.5, label="GT")
ax.grid(True)
ax.set_title("After")
ax.set_ylabel("")
ax.set_xlabel('Distances')
ax.legend()
if save is None:
pylab.show()
else:
pylab.savefig(save)
pylab.close(fig)
return