修改字体和颜色
This commit is contained in:
40
chart.py
40
chart.py
@@ -40,13 +40,15 @@ def add_cci(df, chart, period: int = 14, height: float = 0.1, position: str = "b
|
||||
cci_chart = chart.create_subchart(
|
||||
position=position, width=1, height=height, sync=True
|
||||
)
|
||||
cci_chart.legend(visible=True)
|
||||
cci_chart.legend(
|
||||
visible=True, font_size=14, color="#FFFFFF", font_family="Times New Roman"
|
||||
)
|
||||
cci_chart.time_scale(visible=False)
|
||||
cci_line = cci_chart.create_line(name="cci", color="#FF5722", width=2)
|
||||
cci_line = cci_chart.create_line(name="cci", color="#FF0000", width=2)
|
||||
cci_line.set(df[["time", "cci"]])
|
||||
|
||||
|
||||
def add_macd(df, chart, height: float = 0.2, position: str = "bottom"):
|
||||
def add_macd(df, chart, height: float = 0.1, position: str = "bottom"):
|
||||
macd, signal, hist = ta.MACD(
|
||||
df["close"], fastperiod=12, slowperiod=26, signalperiod=9
|
||||
)
|
||||
@@ -56,19 +58,21 @@ def add_macd(df, chart, height: float = 0.2, position: str = "bottom"):
|
||||
macd_chart = chart.create_subchart(
|
||||
position=position, width=1, height=height, sync=True
|
||||
)
|
||||
macd_chart.legend(visible=True)
|
||||
macd_chart.legend(
|
||||
visible=True, font_size=14, color="#FFFFFF", font_family="Times New Roman"
|
||||
)
|
||||
macd_chart.time_scale(visible=False)
|
||||
|
||||
histogram = macd_chart.create_histogram(name="histogram")
|
||||
hist_data = df[["time", "histogram"]].copy()
|
||||
hist_data["color"] = hist_data["histogram"].apply(
|
||||
lambda x: "#26a69a" if x < 0 else "#ef5350" # 绿色 : 红色
|
||||
lambda x: "#00FF00" if x < 0 else "#ff0000" # 绿色 : 红色
|
||||
)
|
||||
histogram.set(hist_data)
|
||||
|
||||
macd_line = macd_chart.create_line(name="macd", color="#2962FF", width=2)
|
||||
macd_line.set(df[["time", "macd"]])
|
||||
signal_line = macd_chart.create_line(name="signal", color="#FF6D00", width=2)
|
||||
signal_line = macd_chart.create_line(name="signal", color="#FF0000", width=2)
|
||||
signal_line.set(df[["time", "signal"]])
|
||||
|
||||
|
||||
@@ -108,9 +112,9 @@ def add_TD(df, chart):
|
||||
markers.append(
|
||||
{
|
||||
"time": item["time"].strftime("%Y-%m-%d"),
|
||||
"position": "below",
|
||||
"shape": "arrow_up",
|
||||
"color": "#4CAF50",
|
||||
"position": "above",
|
||||
"shape": "arrow_down",
|
||||
"color": "#00FF00",
|
||||
"text": f"{item['TD']}",
|
||||
}
|
||||
)
|
||||
@@ -118,9 +122,9 @@ def add_TD(df, chart):
|
||||
markers.append(
|
||||
{
|
||||
"time": item["time"].strftime("%Y-%m-%d"),
|
||||
"position": "above",
|
||||
"shape": "arrow_down",
|
||||
"color": "#F44336",
|
||||
"position": "below",
|
||||
"shape": "arrow_up",
|
||||
"color": "#FF0000",
|
||||
"text": f"{item['TD']}",
|
||||
}
|
||||
)
|
||||
@@ -142,7 +146,7 @@ def add_buy_sell_signal_markers(df, chart):
|
||||
"time": item["time"].strftime("%Y-%m-%d"),
|
||||
"position": "below",
|
||||
"shape": "arrow_up",
|
||||
"color": "#4CAF50",
|
||||
"color": "#00FF00",
|
||||
"text": f"B",
|
||||
}
|
||||
)
|
||||
@@ -152,7 +156,7 @@ def add_buy_sell_signal_markers(df, chart):
|
||||
"time": item["time"].strftime("%Y-%m-%d"),
|
||||
"position": "above",
|
||||
"shape": "arrow_down",
|
||||
"color": "#F44336",
|
||||
"color": "#FF0000",
|
||||
"text": f"S",
|
||||
}
|
||||
)
|
||||
@@ -231,13 +235,15 @@ def plot_chart(df, symbol: str, name: str, timeframe: str):
|
||||
time, open, high, low, close, volume, [buy, sell]可选 buy=1 买入信号, sell=1 卖出信号
|
||||
|
||||
"""
|
||||
chart = Chart(toolbox=True, inner_height=0.7, maximize=True)
|
||||
chart = Chart(toolbox=True, inner_height=0.6, maximize=True)
|
||||
|
||||
chart.topbar.textbox("symbol", symbol)
|
||||
chart.topbar.textbox("name", name)
|
||||
chart.topbar.textbox("timeframe", timeframe)
|
||||
|
||||
chart.legend(visible=True)
|
||||
chart.legend(
|
||||
visible=True, font_size=14, color="#FFFFFF", font_family="Times New Roman"
|
||||
)
|
||||
|
||||
chart.set(df)
|
||||
add_ema(df, chart, period=10)
|
||||
@@ -253,7 +259,7 @@ def plot_chart(df, symbol: str, name: str, timeframe: str):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
symbol = "931357"
|
||||
symbol = "399986"
|
||||
timeframe = "1W"
|
||||
|
||||
df = pd.read_csv(
|
||||
|
||||
Reference in New Issue
Block a user