Candlestick chart add_trace(mode=“markers”) gives wrong output

I’m currently building a financial dashboard with dash and plotly. I added the following candlestick chart to my dashboard:

    candlestick_chart = go.Figure(data=[go.Candlestick(x=financial_data["Date"],
                                     open=financial_data['Open'],
                                     high=financial_data['High'],
                                     low=financial_data['Low'],
                                     close=financial_data['Close'])])

Which returns the expected result: enter image description here

I would like to be able to highlight specific candlesticks (e.g. with a marker)

I tried to achieve this with the add_trace function and the following code:

    candlestick_chart.add_trace(
    go.Scatter(
        x=["2020-07-01"],
        y=["350"],
        mode="markers",
        marker=dict(symbol="6")

    )
)

But this ruins the chart.

enter image description here

Why does that happen? How can I fix this?

EDIT: ADDED DATASOURCE

I got the data from https://finance.yahoo.com/quote/SPY/history?p=SPY with Time period set to max.

I parsed the data the following way:

    start = "2000-01-01"
end = "2021-01-01"

# Get a pandas dataframe
datapath = ('D:\Programmieren\trading_bot\etf_data\SPY.csv')

financial_data = pd.read_csv(datapath,
                             parse_dates=True,
                             index_col=0)

financial_data= financial_data.loc[start:end]
# Process data
financial_data = financial_data["2020-06-01":"2021-01-01"]

financial_data.reset_index(inplace=True)

EDIT2: SYSTEM AND VERSIONS

My packages have the following versions:

print(pd.__version__) # 1.2.3
print(plotly.__version__) # 4.14.3

And I am working with:

  • Windows 10 Home (64-Bit)
  • Python 3.9
  • Python 3.8 doesn’t work either

Answer

This could be regarded as a version issue, but the core problem is that you’ve defined your y-value as a list of strings with ["350"] instead of a number like [350] in:

go.Scatter(
        x=["2020-07-01"],
        y=["350"],
        mode="markers",
        marker=dict(symbol="6")

    )
)

Different versions of plotly seems to handle this differently. Simply remove the quotation marks to let plotly interpret the value as a number instead to produce this:

enter image description here

Complete code with sample data

import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd

# data
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
df=df.tail(10)

# set up figure with values not high and not low
# include candlestick with rangeselector
fig = go.Figure(go.Candlestick(x=df['Date'],
                open=df['AAPL.Open'], high=df['AAPL.High'],
                low=df['AAPL.Low'], close=df['AAPL.Close']))

fig.add_trace(
    go.Scatter(
        x=["2017-02-10"],
        y=[135],
        mode="markers+text",
        marker=dict(symbol='triangle-down-open', size = 12),
#         text = 'important',
#         textposition = 'middle right'

    )
)

fig.show()