Open nicolaskruchten opened 4 years ago
The syntax is
import plotly.express as px
df = px.data.stocks()
fig = px.line(df, x=df.date, y=df.columns[1:], hover_data={'index': ("|%B %d, %Y", df.index)} )
fig.show()
Is this what you were asking? The keys of the hover_data
dict need to be str or numbers.
So that works to add a new entry to the hoverlabel with label "index" but in my use-case is that in wide-form the index of df
is used by default (in this case it's called "date"
) and I can't format that hover entry:
Ah but you're totally right, this does work:
import plotly.express as px
df = px.data.stocks(indexed=True)
fig = px.line(df, hover_data={"date": ("|%Y", df.index)})
fig.show()
Or more generally: hover_data={df.index.name: ("|%Y", df.index)}
... pretty obscure tho! Not sure where to document that one.
Or more generally:
hover_data={df.index.name: ("|%Y", df.index)}
... pretty obscure tho! Not sure where to document that one.
this works for single index, what about multiple index?
Or more generally:
hover_data={df.index.name: ("|%Y", df.index)}
... pretty obscure tho! Not sure where to document that one.
Yes the reference to the general syntax for the formatting part of the tuple would be very appreciated. I finally found that the correct syntax for a literal string was {"index": (df.index)}
but I had to fumble a lot.
In wide-mode I can't do this:
or find any other way of referring to the index.