From deb4ce7a0b823f6aa96dc647a58fee12f951c5e6 Mon Sep 17 00:00:00 2001 From: aszerW Date: Sun, 19 Oct 2025 13:43:07 +0800 Subject: [PATCH] =?UTF-8?q?macd=20hist=E9=80=8F=E6=98=8E=E5=BA=A6=E8=B0=83?= =?UTF-8?q?=E6=88=900.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chart.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/chart.py b/chart.py index 4e6ab58..d8c1102 100644 --- a/chart.py +++ b/chart.py @@ -224,17 +224,21 @@ class QuantChart: histogram = macd_chart.create_histogram(name=macd_name) hist_data = df[["time", macd_name]].copy() - hist_data['prev_value'] = hist_data[macd_name].shift(1) - # 设置颜色逻辑 + hist_data["prev_value"] = hist_data[macd_name].shift(1) + + # 设置颜色逻辑 def get_histogram_color(row): - current, prev = row[macd_name], row['prev_value'] - is_hollow = (current >= 0 and current < prev) or (current < 0 and current > prev) + current, prev = row[macd_name], row["prev_value"] + is_hollow = (current >= 0 and current < prev) or ( + current < 0 and current > prev + ) if current >= 0: - return "rgba(255, 0, 0, 0.3)" if is_hollow else "#ff0000" + return "rgba(255, 0, 0, 0.5)" if is_hollow else "#ff0000" else: - return "rgba(0, 255, 0, 0.3)" if is_hollow else "#00FF00" - hist_data["color"] = hist_data.apply(get_histogram_color, axis=1) - hist_data = hist_data.drop('prev_value', axis=1) + return "rgba(0, 255, 0, 0.5)" if is_hollow else "#00FF00" + + hist_data["color"] = hist_data.apply(get_histogram_color, axis=1) + hist_data = hist_data.drop("prev_value", axis=1) histogram.set(hist_data)