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})")