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)