- 安装mplfinance、yfinance依赖
pip install mplfinance mplfinance
- 使用python生成股票烛台图(Candlestick Chart Plot)
import mplfinance as mpf
import yfinance as yf
# Define the stock symbol and date range
# symbol = input("Enter Stock Name : ")
start_date = '2024-01-01'
end_date = '2024-09-30'
# Fetch stock data
stock_data = yf.download('000001.SS', start=start_date, end=end_date)
# Create a custom style with modified font sizes for axis ticks
my_style = mpf.make_mpf_style(
base_mpf_style='yahoo', # Use Yahoo Finance style as base
rc={'xtick.labelsize': 17, 'ytick.labelsize': 17} # Set font size for x and y ticks
)
# Create the candlestick chart
mpf.plot(stock_data, type='candle', style=my_style, title='000001.SS Candlestick Chart', figsize=(16, 9))
- type 参数:type 决定了你要绘制的图表类型,常见类型有candle、ohlc、line。
- style 参数:style 决定了图表的颜色、背景、网格线等视觉样式,一些常用的样式包括yahoo、classic、blueskies、nightclouds、mike。
- 输出结果

© 版权声明
文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...