fix: K线图示例与main.py配置保持一致
优化内容: - 统一股票代码列表: 使用与main.py相同的 ['601658.SH', '510310.SH', '601398.SH'] - 统一数据周期列表: 使用与main.py相同的 ['1m', '5m', '15m', '30m', '60m', '1d'] - 统一时间范围: 使用与main.py相同的 20250501 ~ 20250721 - 添加配置变量说明: 明确标识配置来源于main.py - 增强示例输出: 显示使用的具体配置参数 这样确保K线图绘制的数据来源与数据处理模块完全一致,避免参数不匹配导致的问题
This commit is contained in:
parent
f2ee378da0
commit
ae2e4c0ec9
@ -2,6 +2,7 @@
|
|||||||
K线图绘制使用示例
|
K线图绘制使用示例
|
||||||
|
|
||||||
演示如何使用 plot_kline.py 模块绘制股票K线图
|
演示如何使用 plot_kline.py 模块绘制股票K线图
|
||||||
|
配置与main.py保持一致,确保数据来源和参数统一
|
||||||
|
|
||||||
使用方法:
|
使用方法:
|
||||||
1. 直接运行此文件
|
1. 直接运行此文件
|
||||||
@ -11,16 +12,26 @@ K线图绘制使用示例
|
|||||||
|
|
||||||
from plot_kline import plot_kline_interactive
|
from plot_kline import plot_kline_interactive
|
||||||
|
|
||||||
|
# 从main.py中导入相同的配置,保持一致性
|
||||||
|
g_stock_code_list = ["601658.SH", "510310.SH", "601398.SH"] # 与main.py相同
|
||||||
|
g_period_list = ["1m", "5m", "15m", "30m", "60m", "1d"] # 与main.py相同
|
||||||
|
g_start_date = "20250501" # 与main.py相同
|
||||||
|
g_end_date = "20250721" # 与main.py相同
|
||||||
|
|
||||||
def example_single_stock():
|
def example_single_stock():
|
||||||
"""单个股票K线图示例"""
|
"""单个股票K线图示例 - 使用与main.py相同的配置"""
|
||||||
print("🎯 单个股票K线图示例")
|
print("🎯 单个股票K线图示例")
|
||||||
print("=" * 40)
|
print("=" * 40)
|
||||||
|
|
||||||
# 参数设置
|
# 使用与main.py相同的配置参数
|
||||||
stock_code = "601658.SH" # 邮储银行
|
stock_code = g_stock_code_list[0] # 601658.SH 邮储银行
|
||||||
period = "1d" # 日线
|
period = "1d" # 日线
|
||||||
start_date = "20250501" # 开始日期
|
start_date = g_start_date # 20250501
|
||||||
end_date = "20250721" # 结束日期
|
end_date = g_end_date # 20250721
|
||||||
|
|
||||||
|
print(f"📊 股票代码: {stock_code}")
|
||||||
|
print(f"📈 数据周期: {period}")
|
||||||
|
print(f"📅 时间范围: {start_date} ~ {end_date}")
|
||||||
|
|
||||||
# 绘制K线图
|
# 绘制K线图
|
||||||
success = plot_kline_interactive(
|
success = plot_kline_interactive(
|
||||||
@ -38,14 +49,19 @@ def example_single_stock():
|
|||||||
|
|
||||||
|
|
||||||
def example_multiple_periods():
|
def example_multiple_periods():
|
||||||
"""多周期K线图示例"""
|
"""多周期K线图示例 - 使用与main.py相同的配置"""
|
||||||
print("\n🎯 多周期K线图示例")
|
print("\n🎯 多周期K线图示例")
|
||||||
print("=" * 40)
|
print("=" * 40)
|
||||||
|
|
||||||
stock_code = "510310.SH" # 沪深300ETF
|
# 使用与main.py相同的配置
|
||||||
periods = ["1m", "5m", "15m", "30m", "1d"]
|
stock_code = g_stock_code_list[1] # 510310.SH 沪深300ETF
|
||||||
start_date = "20250701"
|
periods = g_period_list # 与main.py相同的周期列表
|
||||||
end_date = "20250721"
|
start_date = g_start_date # 20250501
|
||||||
|
end_date = g_end_date # 20250721
|
||||||
|
|
||||||
|
print(f"📊 股票代码: {stock_code}")
|
||||||
|
print(f"📈 数据周期: {', '.join(periods)}")
|
||||||
|
print(f"📅 时间范围: {start_date} ~ {end_date}")
|
||||||
|
|
||||||
for period in periods:
|
for period in periods:
|
||||||
print(f"\n📈 绘制 {stock_code} 的 {period} 周期K线图...")
|
print(f"\n📈 绘制 {stock_code} 的 {period} 周期K线图...")
|
||||||
@ -64,15 +80,20 @@ def example_multiple_periods():
|
|||||||
|
|
||||||
|
|
||||||
def example_multiple_stocks():
|
def example_multiple_stocks():
|
||||||
"""多股票K线图示例"""
|
"""多股票K线图示例 - 使用与main.py相同的配置"""
|
||||||
print("\n🎯 多股票K线图示例")
|
print("\n🎯 多股票K线图示例")
|
||||||
print("=" * 40)
|
print("=" * 40)
|
||||||
|
|
||||||
stock_codes = ["601658.SH", "510310.SH", "601398.SH"]
|
# 使用与main.py相同的配置
|
||||||
|
stock_codes = g_stock_code_list # 与main.py相同的股票列表
|
||||||
stock_names = ["邮储银行", "沪深300ETF", "工商银行"]
|
stock_names = ["邮储银行", "沪深300ETF", "工商银行"]
|
||||||
period = "1d"
|
period = "1d" # 日线
|
||||||
start_date = "20250601"
|
start_date = g_start_date # 20250501
|
||||||
end_date = "20250721"
|
end_date = g_end_date # 20250721
|
||||||
|
|
||||||
|
print(f"📊 股票代码: {', '.join(stock_codes)}")
|
||||||
|
print(f"📈 数据周期: {period}")
|
||||||
|
print(f"📅 时间范围: {start_date} ~ {end_date}")
|
||||||
|
|
||||||
for stock_code, stock_name in zip(stock_codes, stock_names):
|
for stock_code, stock_name in zip(stock_codes, stock_names):
|
||||||
print(f"\n📈 绘制 {stock_name}({stock_code}) 的K线图...")
|
print(f"\n📈 绘制 {stock_name}({stock_code}) 的K线图...")
|
||||||
@ -129,9 +150,14 @@ def interactive_mode():
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""主函数 - 展示所有示例"""
|
"""主函数 - 展示所有示例,使用与main.py一致的配置"""
|
||||||
print("🚀 K线图绘制工具 - 使用示例")
|
print("🚀 K线图绘制工具 - 使用示例")
|
||||||
print("=" * 50)
|
print("=" * 50)
|
||||||
|
print("📋 配置信息 (与main.py一致):")
|
||||||
|
print(f"📊 股票代码: {', '.join(g_stock_code_list)}")
|
||||||
|
print(f"📈 数据周期: {', '.join(g_period_list)}")
|
||||||
|
print(f"📅 时间范围: {g_start_date} ~ {g_end_date}")
|
||||||
|
print("=" * 50)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 1. 单个股票示例
|
# 1. 单个股票示例
|
||||||
@ -145,6 +171,7 @@ def main():
|
|||||||
|
|
||||||
print("\n🎉 所有示例执行完成!")
|
print("\n🎉 所有示例执行完成!")
|
||||||
print("📁 生成的图表保存在 'charts' 目录中")
|
print("📁 生成的图表保存在 'charts' 目录中")
|
||||||
|
print("💡 提示: 这些配置与main.py保持完全一致")
|
||||||
|
|
||||||
# 4. 交互式模式(可选)
|
# 4. 交互式模式(可选)
|
||||||
user_input = input("\n是否进入交互式模式?(y/n): ").strip().lower()
|
user_input = input("\n是否进入交互式模式?(y/n): ").strip().lower()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user