Simple Python code! Scatter plot not working, version 5.15.0

I can’t use Plotly Express because I need this trace to be added to a Candlestick plot with several financial indicators.

Why doesn’t this work? Did I miss something obvious?

import plotly.graph_objects as go
import pandas as pd

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

df.set_index('Date')
#print(df['Date'].tail())
#print(df.tail())

longEntryTimes = df['Date'].sample(10)
print(longEntryTimes)
under = 0.95
longEntries = [ under * df.loc[df['Date'] == d]['AAPL.Low'] for d in longEntryTimes]
print(longEntries)

fig = go.Figure()
# Should graph 10 triangle markers?
fig.add_trace(go.Scatter(x=longEntryTimes,
                         y=longEntries,
                         mode="markers",
                         marker=dict(
                             symbol="triangle-up",
                             size=15,
                             color="DarkGreen",
                         ),showlegend=False))

fig.show()

Check if the arguments x and y are of type list.

Maybe this is clumsy but this is what fixed it:

longEntries = list(map(lambda x: x.tolist()[0], longEntries))

longEntries was a list of Series objects. This converts it into a list of floats. plotly and pandas do not somehow magically interoperate.

1 Like