Daily hands-on: draw market graphs with python

aims:

Learn to master the method of obtaining the quotation of a specific stock.
At present, it is very good to use the data of Jukuan. You can get the quotation every minute. Tushare can only get the quotation of 5 minutes, so I gave up Tushare to use the quotation of Jukuan.


content:

Draw a market chart to get a graph of price and volume. As shown below, the 2021-1-14 day quotation of the stock code 300001.
Insert picture description here
Icon of market software:
Insert picture description here

The source code is as follows:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from jqdatasdk import *

auth('用户名','密码') #这里用户名密码需要前往聚宽官网自行申请
is_auth = is_auth()
if is_auth == True:
    print("登录成功")
else:
    print("连接失败")
print(__version__)

#获取股票每分钟信息
df = get_price('300001.XSHE', start_date='2021-01-14 09:30:00', end_date='2021-01-14 15:00:00', frequency='minute', fields=['open', 'close','volume'])
#print(df)
print(df['volume'])

x=np.array(df.index)    #时间序列
price=np.array(df['close'])  #用收盘价画图
volume=np.array(df['volume'].values)   #获取成交量
xx=np.arange(0,len(x),1)  # X轴长度
#画图参数
fig = plt.figure()
ax1 = fig.add_subplot(211)
plt.rcParams['font.sans-serif']=['SimHei']  #解决中文乱码
plt.rcParams['axes.unicode_minus'] = False

ax1.set_title('行情')
ax1.plot(xx,price,c='blue')
plt.xlabel('交易时间(分钟)')
plt.ylabel('成交价格(元)')
ax1.legend('成交价格')
plt.grid()

ax2 = fig.add_subplot(212)
ax2.bar(xx,volume,color='deepskyblue',label='left')
ax2.set_ylabel('成交量')
plt.xlabel('交易时间(分钟)')
plt.grid()
ax2.legend('成交量')
#plt.subplots_adjust(left=0.01)
plt.show()


Knowledge points:

Ways and methods to obtain stock market quotations


Learning output:

The basis of data analysis, the mutual conversion of Dateframe and array.

Guess you like

Origin blog.csdn.net/weixin_43290383/article/details/112617750