记录下用python画蜡烛图
import tushare as ts
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import mplfinance as mpf
import numpy as np
from datetime import datetimets.set_token('your token')
pro = ts.pro_api()
df = pro.daily(ts_code='000001.SZ', start_date='20180701', end_date='20180718')
df['date'] = df['trade_date'].apply(lambda x: datetime.strptime(x, '%Y%m%d'))
data = https://www.it610.com/article/df.loc[:,['date', 'open','close','high','low','vol']]
data = https://www.it610.com/article/data.rename(columns={"vol": "volume"})
data.set_index('date', inplace=True)
data.index.name = "Date"
data.index = pd.DatetimeIndex(data.index)
data=https://www.it610.com/article/data.reindex(index=data.index[::-1])# data.head
mc = mpf.make_marketcolors(up='r',down='g')
s= mpf.make_mpf_style(marketcolors=mc,mavcolors=['#4f8a8b','#fbd46d','#87556f'])mpf.plot(data,type='candle',volume=True, show_nontrading=True, figratio=(20,10), mav=(5,10,15),style=s)
文章图片
如何获取数据:
https://tushare.pro/register?reg=332190
画图:
https://github.com/matplotlib/mplfinance
【最新版mplfinance画股市蜡烛图】https://github.com/matplotlib/mplfinance/blob/master/examples/styles.ipynb
推荐阅读
- 用Tushare获取A股所有股票历史数据
- Python数据分析环境搭建
- 学习资料记录|python学习 - 图标签用宋体&Times New Roman字体 + 规范的混淆矩阵绘制
- 学习资料记录|故障诊断方向 - 就业企业推荐
- 蓝桥杯Python|蓝桥杯VIP题目免费提交,内含超详解,步步截图!!!
- 如何将多张图片合成mp4视频格式,并加入背景音乐...
- python|python import 搜索包路径的机制,以及添加自定义python包的方法
- 社区发现|CommDGI: Community detection oriented deep graph infomax 2020 CIKM
- android|android-19_如何在Android上关闭COVID-19曝光跟踪和通知