I am plotting a heatmap with some custom data, using a dataframe to store the values. I know that as my values increase I will need to use the customdata param to specify the hover effect.
With go.Scatter, this works as described:
def scatter_drawdown(df, x="Datetime", y=Price, color=["black"]):
# customdata
dt = pd.Series([(str(t.month_name())[:3] + " " + str(t.day) + ", " + str(
t.hour)[:2] + ":" + "0" + str(t.minute)) if len(str(t.minute)) < 2 else
(str(t.month_name())[:3] + " " + str(t.day) + ", " + str( t.hour)[:2] +
":" + str(t.minute)) for t in df[x]])
y0 = pd.Series([round(f, 2) for f in df[y]])
d0 = pd.Series(df["5_Day_Drawdown"])
tk = pd.Series(df["Ticker"])
pc = pd.Series([Price]*len(df))
# trace
trace0 = go.Scatter(
x=df[x],
y=y0.values,
customdata=pd.concat([tk, dt, d0, pc], axis=1),
name=tk.values[0],
hovertemplate=
"<b>%{customdata[0]}</b><br>" +
"%{customdata[3]}: $%{y}<br>" +
"Time: %{customdata[1]}<br>" +
"Drawdown: %{customdata[2]}<br>" +
"<extra></extra>",
showlegend=True,
marker={"color":color, "opacity": 1.00},
)
return trace0
However, when I use the same parameter logic with go.Heatmap, the code breaks.
tit = pd.Series(df["Ticker"])
pc = pd.Series([Price]*len(df))
trace1 = go.Histogram2d(
x = gb[tx1],
y = gb["Time"],
z = gb[dollars_baby],
histfunc="avg",
customdata=pd.concat([tit, pc], axis=1),
hovertemplate=
"<b>Average %{customdata[1]}: $%{z}</b><br>" +
"Time: %{y}<br>" +
"Day: %{x}<br>" +
"<extra></extra>",
colorscale=colorscale
)
Please let me know the best way to coallate the information to the customdata param. Passing it into an array seems unnecessarily complex.