绘制价格和标签

时间:2019-01-28 03:36:01

标签: matplotlib plot

我有一个股票价格清单和一个等长标签清单。 3种可能的标签是-101,其中-11代表价格上涨或下跌的位置。

我创建了该功能,该功能允许在价格上涨或下跌时在关联的价格上放置绿色和红色的点,但是它不能按预期工作。

def plot(price, labels):
    green1 = []
    redm1 = []
    for i in range(len(labels)):
        y = labels[i]

        if y == -1:
            green1.append(price[1])
            redm1.append(None)
        elif y == 1:
            redm1.append(price[1])
            green1.append(None)
        else:
            green1.append(None)
            redm1.append(None)


    plt.subplot(1, 1, 1)
    plt.plot(range(price.shape[0]), price, color="orange")
    plt.plot(range(price.shape[0]), green1, "o", color="green")
    plt.plot(range(price.shape[0]), redm1, "o", color="red")
    plt.title("Plot")
    plt.show()
    plt.clf()

enter image description here

请注意,红线点不仅是红点,而且是绿点。

如何修复plot函数,以便可以将点放置在曲线上而不是直线上?

0 个答案:

没有答案