如何在情节烛台图上绘制绿色和红色箭头?

时间:2018-02-28 05:48:14

标签: python python-2.7 plotly

我尝试使用带有Python的plotly库为我的数据绘制蜡烛棒。使用典型的绘图方式,我得到了以下图表:

Candle = go.Candlestick(x=stock.index,
                       open=stock.open,
                       high=stock.high,
                       low=stock.low,
                       close=stock.close
                       )

输出:
candles image

我期待画出的图像如下:
candles with arrow

查看向上的绿色箭头和向下的红色箭头。我想知道如何绘制它。

1 个答案:

答案 0 :(得分:1)

我不知道哪一个是选择箭头的逻辑,但你可以从这里开始玩。首先从Yahoo-finance TESLA然后

下载数据
import plotly.offline as py
import plotly.graph_objs as go
import pandas as pd
import numpy as np
stock =  pd.read_csv("~/Downloads/TSLA.csv")

d=3
stock["Marker"] = np.where(stock["Open"]<stock["Close"], stock["High"]+d, stock["Low"]-d)
stock["Symbol"] = np.where(stock["Open"]<stock["Close"], "triangle-up", "triangle-down")
stock["Color"] = np.where(stock["Open"]<stock["Close"], "green", "red")

Candle = go.Candlestick(x=stock.Date,
                       open=stock.Open,
                       high=stock.High,
                       low=stock.Low,
                       close=stock.Close
                       )

Trace = go.Scatter(x=stock.Date,
                   y=stock.Marker,
                   mode='markers',
                   name ='markers',
                   marker=go.Marker(size=20,
                                    symbol=stock["Symbol"],
                                    color=stock["Color"])
                   )
py.plot([Candle, Trace])