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)

上一篇:前端一些好用的小小工具,持续更新中…


下一篇:Android ios渐变实现