当 True 时在蜡烛上方绘制标记 - Plotly

时间:2021-05-28 19:41:18

标签: python plotly

问题

df["Close Above Open"]True 时,如何在蜡烛上方绘制标记(箭头、点或类似物)

当前图表

current chart

期望输出

desired output

可重现的示例代码

import pandas as pd
import numpy as np
import plotly.graph_objects as go

def genMockDataFrame(days,startPrice,colName,startDate,seed=None): 
   
    periods = days*24
    np.random.seed(seed)
    steps = np.random.normal(loc=0, scale=0.0018, size=periods)
    steps[0]=0
    P = startPrice+np.cumsum(steps)
    P = [round(i,4) for i in P]

    fxDF = pd.DataFrame({ 
        'ticker':np.repeat( [colName], periods ),
        'date':np.tile( pd.date_range(startDate, periods=periods, freq='H'), 1 ),
        'price':(P)})
    fxDF.index = pd.to_datetime(fxDF.date)
    fxDF = fxDF.price.resample('D').ohlc()
    fxDF.columns = [i.title() for i in fxDF.columns]
    return fxDF


df = genMockDataFrame(15,1.1904,'eurusd','19/3/2020',seed=157)

df["Close Above Open"] = df.apply(lambda x: x.Close >= x.Open,axis=1)

fig = go.Figure(data=[go.Candlestick(x=df.index,

                open=df['Open'],
                high=df['High'],
                low=df['Low'],
                close=df['Close'])])



fig.show()

1 个答案:

答案 0 :(得分:1)

family_id