import numpy as np
from matplotlib import pyplot as plt
# 显示K线
def show_k_lines(df) -> None:
# 判断收盘价与开盘价 确定蜡烛颜色
colors_bool = df['Close'] >= df['Open']
colors = np.zeros(colors_bool.size, dtype='U5')
colors[:] = 'green'
colors[colors_bool] = 'white'
# 确定蜡烛边框颜色
edge_colors = np.zeros(colors_bool.size, dtype='U5')
edge_colors[:] = 'g'
edge_colors[colors_bool] = 'red'
plt.bar(df.index, (df['Close'] - df['Open']), 0.8, bottom=df['Open'], color=colors, edgecolor=edge_colors, zorder=2)
# 绘制上下引线
plt.vlines(df.index, df['Low'], df['High'], color=edge_colors, zorder=1)