macd hist透明度调成0.5
This commit is contained in:
20
chart.py
20
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user