From 4223c4b79982ff2d5c8398c631975dbed5ea269d Mon Sep 17 00:00:00 2001 From: cuizhan <3971687@qq.com> Date: Mon, 28 Jul 2025 16:44:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96K=E7=BA=BF=E5=9B=BE=E8=A1=A8?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=95=88=E6=9E=9C=EF=BC=9A=E5=A2=9E=E5=BC=BA?= =?UTF-8?q?=E5=9D=87=E7=BA=BF=E9=85=8D=E7=BD=AE=E5=92=8C=E9=BB=91=E8=89=B2?= =?UTF-8?q?=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增功能: - 新增30日和60日移动平均线支持 - 完整的5条均线配置:MA5, MA10, MA20, MA30, MA60 视觉优化: - 实现专业黑色主题:图表背景、坐标轴、文本全部适配 - 优化均线颜色方案:5日白色,10日黄色,20日粉色,30日荧光绿,60日荧光蓝 - 增强MACD显示:快线白色,信号线黄色,零轴线白色 - 提升网格线和文本在黑色背景下的可读性 技术改进: - 采用字典映射实现颜色配置,更易维护和扩展 - 统一所有图表元素的黑色主题适配 - 保持专业金融软件的视觉风格 --- src/data_process_model/stock_kline_viewer.py | 37 +++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/data_process_model/stock_kline_viewer.py b/src/data_process_model/stock_kline_viewer.py index dc486c0..405c4f5 100644 --- a/src/data_process_model/stock_kline_viewer.py +++ b/src/data_process_model/stock_kline_viewer.py @@ -50,6 +50,17 @@ class KlineChartRenderer: plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False + # 设置黑色背景主题 + plt.rcParams['figure.facecolor'] = 'black' # 图表整体背景 + plt.rcParams['axes.facecolor'] = 'black' # 子图背景 + plt.rcParams['axes.edgecolor'] = 'white' # 坐标轴边框颜色 + plt.rcParams['axes.labelcolor'] = 'white' # 坐标轴标签颜色 + plt.rcParams['xtick.color'] = 'white' # x轴刻度颜色 + plt.rcParams['ytick.color'] = 'white' # y轴刻度颜色 + plt.rcParams['text.color'] = 'white' # 文本颜色 + plt.rcParams['grid.color'] = 'gray' # 网格线颜色 + plt.rcParams['grid.alpha'] = 0.3 # 网格线透明度 + # 图表配置 self.figure_size = (15, 10) @@ -222,13 +233,21 @@ class KlineChartRenderer: if not ma_dict: return - colors = ['orange', 'purple', 'brown', 'pink', 'gray'] - ma_periods = params.ma_periods if params else [5, 10, 20] + # MA线颜色配置:5日白色,10日黄色,20日粉色,30日荧光绿,60日荧光蓝 + ma_colors = { + 5: 'white', # 5日线:白色 + 10: 'yellow', # 10日线:黄色 + 20: 'magenta', # 20日线:粉色 + 30: 'lime', # 30日线:荧光绿 + 60: 'cyan' # 60日线:荧光蓝 + } + ma_periods = params.ma_periods if params else [5, 10, 20, 30, 60] for i, period_val in enumerate(ma_periods): ma_key = f'ma{period_val}' if ma_key in ma_dict: - color = colors[i % len(colors)] + # 使用预定义的颜色,如果没有则使用默认颜色 + color = ma_colors.get(period_val, 'gray') ma_series = ma_dict[ma_key] # 过滤掉NaN值 @@ -263,15 +282,15 @@ class KlineChartRenderer: x_range = range(len(macd_line)) # 绘制MACD线和信号线 - ax.plot(x_range, macd_line, label='MACD', color='blue', linewidth=1.5) - ax.plot(x_range, signal_line, label='Signal', color='red', linewidth=1.5) + ax.plot(x_range, macd_line, label='MACD', color='white', linewidth=1.5) + ax.plot(x_range, signal_line, label='Signal', color='yellow', linewidth=1.5) # 绘制MACD柱状图 colors = ['red' if h >= 0 else 'green' for h in histogram] ax.bar(x_range, histogram, color=colors, alpha=0.6, width=0.8, label='Histogram') # 添加零轴线 - ax.axhline(y=0, color='black', linestyle='-', alpha=0.3) + ax.axhline(y=0, color='white', linestyle='-', alpha=0.5) # 设置图例 if params: @@ -424,7 +443,7 @@ def main(): # 测试股票代码列表 test_stocks = ['601658.SH', '601398.SH'] - test_period = '1d' + test_period = '60m' # 方式1: 设置具体的起止时间 start_date, end_date = '2025-01-01', '2025-07-28' @@ -440,14 +459,14 @@ def main(): params = None if IndicatorParams is not None: params = IndicatorParams( - ma_periods=[5, 10, 20], # 移动平均线周期:适合日线 + ma_periods=[5, 10, 20, 30, 60], # 移动平均线周期:5日、10日、20日、30日、60日 macd_fast=6, # MACD快线 macd_slow=13, # MACD慢线 macd_signal=5 # MACD信号线 ) print(f"📅 数据时间范围: {start_date} ~ {end_date if end_date else '最新数据'}") - print(f"📊 技术指标配置: MA{params.ma_periods if params else [5,10,20]}, MACD(12,26,9)") + print(f"📊 技术指标配置: MA{params.ma_periods if params else [5,10,20,30,60]}, MACD(6,13,5)") for stock_code in test_stocks: print(f"\n🔍 查看股票: {stock_code} ({test_period})")