我尝试使用带有Python的plotly
库为我的数据绘制蜡烛棒。使用典型的绘图方式,我得到了以下图表:
Candle = go.Candlestick(x=stock.index,
open=stock.open,
high=stock.high,
low=stock.low,
close=stock.close
)
查看向上的绿色箭头和向下的红色箭头。我想知道如何绘制它。
答案 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])