编程语言
首页 > 编程语言> > python通达信,显示K线图

python通达信,显示K线图

作者:互联网

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)

标签:线图,plt,python,colors,df,通达信,edge,bool,np
来源: https://blog.csdn.net/qq_38242953/article/details/120204915