#!/usr/bin/python
#coding=utf-8
#import talib
import numpy as np
import pandas as pd
import tushare as ts
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
df = ts.get_h_data('002323', start='2018-01-01', end='2019-01-05', autype=None)
fig, ax = plt.subplots()
ax.set_title(u'股价走势图')
ax.set_ylabel(u'股价')
ax.set_xlabel(u'日期')
#ax.plot(df.index.values, df['close'].values,'r')#画一张图
#ax.plot(df.index.values, df['close'].values,'r',df.index.values,df['low'].values,'k')#画两张图
#画两张图的另一种方式:
ax.plot(df.index.values, df['close'].values,'r',label='Close')
ax.plot(df.index.values, df['low'].values,'k',label='Low')
plt.legend() # 展示图例
plt.show()
#共享x轴:
#!/usr/bin/python
#coding=utf-8
#import talib
import numpy as np
import pandas as pd
import tushare as ts
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']#用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
df = ts.get_hist_data('000166', start='2018-01-03', end='2019-09-30')
n = pd.to_datetime(df.index)
sh = ts.get_hist_data('sh', start='2018-01-03', end='2019-09-30')
fig, ax = plt.subplots()
ax.set_title(u'trend of 000166')
ax.set_ylabel(u'Price',color='b')
ax.set_xlabel(u'date')
ax.plot(n.values, df['close'].values,'r',label='Close')
ax.plot(n.values, df['ma5'].values,'k',label='ma5')
ax.plot(n.values, df['ma10'].values,'b',label='ma10')
#ax2 = ax.twinx()
#ax2.plot(n.values, sh['close'].values,'g',label='SH')
#ax2.set_ylabel(u'SH',color='r')
plt.legend()
plt.show()
子图:
#!/usr/bin/python
#coding=utf-8
#import talib
import numpy as np
import pandas as pd
import tushare as ts
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
x = np.linspace(0, 2 * np.pi, 50)
plt.subplot(2, 2, 1) # (行,列,活跃区)
plt.plot(x, np.sin(x), 'r')
plt.subplot(2, 2, 3)
plt.plot(x, np.cos(x), 'g')
plt.show()
聚宽上用JQdata :
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
df = get_price('000750.XSHE', count = 365, end_date='2019-01-07', frequency='daily', fields=['open', 'close'])
plt.plot(df.index.values, df['close'].values,'b')
help :
https://www.joinquant.com/help/api/help?name=JQData#get_security_info-%E8%8E%B7%E5%8F%96%E5%8D%95%E4%B8%AA%E6%A0%87%E7%9A%84%E4%BF%A1%E6%81%AF
以下内容是找当日的ZT:
Alllist = list (get_all_securities(date='2018-01-07').index)# all of A
#未去除ST、新G等
list_ZT= {}
list_current_zt=[]
for s in Alllist:
df = get_price(s,start_date='2019-01-07', end_date='2019-01-07', fields=['close', 'high_limit', 'paused'])
for i in range(1,len(df.index)+1):
if df['paused'][-i] == False:
if df['close'][-i]>=df['high_limit'][-i]:
list_current_zt.append(s)
print (list_current_zt)
list_ZT= {}
for s in list_current_zt:
df = get_price(s,start_date='2018-12-26', end_date='2019-01-07', fields=['close', 'high_limit', 'paused'])
for i in range(1,len(df.index)+1):
if df['paused'][-i] == False:
if df['close'][-i]>=df['high_limit'][-i]:
if s not in list_ZT:
list_ZT[s]=[]
list_ZT[s].append(df.index[-i])
else:
list_ZT[s].append(df.index[-i])
print (list_ZT)
print (len(list_ZT))
list_ZT_num={}
for s in list_ZT:
list_ZT_num[s]=len(list_ZT[s])
print( "%s涨停%s次"%(s,len(list_ZT[s])))
#按涨停次数排序
list_zt= sorted(list_ZT_num.items(), key=lambda list_ZT_num:list_ZT_num[1],reverse=True)
print(list_zt)
xf = pd.DataFrame(list_zt, columns=["code", "days"])
提高效率:
Alllist = list (get_all_securities(date=‘2018-01-07’).index)# all of A
为何要吧index 转化成List ?
list_current_zt =[]
for s in df.index :
df = get_price(s,start_date='2019-02-18', end_date='2019-02-18', fields=['close', 'high_limit', 'paused'])
for i in range(1,len(df.index)+1):
if df['paused'][-i] == False:
if df['close'][-i]>=df['high_limit'][-i]:
list_current_zt.append(s)
GOOD :
https://www.tubeoffline.com/download-PornHub-videos.php
import matplotlib.pyplot as plt
import matplotlib.patches as mpatch
import numpy as np
M= np.array([[1,2,3],[4,5,6]])
print (M)
print(M[1,2])# 6
a = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print(a.shape) #结果返回一个tuple元组 (2L, 5L)
print(a.shape[0]) #获得行数,返回 2
print(a.shape[1]) #获得列数,返回 5
fig, ax = plt.subplots()
rectangles = {'skinny' : mpatch.Rectangle((2,2), 8, 2),
'square' : mpatch.Rectangle((4,6), 6, 6)}
for r in rectangles:
ax.add_artist(rectangles[r])
rx, ry = rectangles[r].get_xy()
cx = rx + rectangles[r].get_width()/2.0
cy = ry + rectangles[r].get_height()/2.0
ax.annotate(r, (cx, cy), color='w', weight='bold',
fontsize=8, ha='center', va='center')
#ax.set_xlim((-10, 20))
#ax.set_ylim((-10, 20))
plt.axis([-10, 20, -10, 20]) #等价于上面两句
ax.set_aspect('equal')
plt.grid(True)#True加网格
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.title('Fucking plot')
plt.show()