使用python生成股票烛台图(Candlestick Chart Plot)

阿里云教程3个月前发布
27 0 0
  1. 安装mplfinanceyfinance依赖
pip install mplfinance mplfinance
  1. 使用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 决定了你要绘制的图表类型,常见类型有candleohlc、line
  • style 参数:style 决定了图表的颜色、背景、网格线等视觉样式,一些常用的样式包括yahooclassicblueskiesnightcloudsmike。
  1. 输出结果

使用python生成股票烛台图(Candlestick Chart Plot)

© 版权声明

相关文章

暂无评论

none
暂无评论...