-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DateTime object not rendered correctly in plot tooltip #2518
Comments
Where you input your date to the tooltip, I'm assuming you're doing something like:
Try converting the series to a normal array with '.values' like:
|
I was plotting it via plotly express. However, I tried passing in the Timestamp.values (instead of |
Plotly allows you passing in a formatting string when using
However, I noticed this does not work if I needed to "cast" the DateTime object to string, and only then it worked:
It took me a while to figure this out as, intuitively, I would have assumed this transformation to be done implicitly. Maybe this could be added as a feature? |
I have a similar problem, definitely a bug. dtypes for "Start" and "Finish are I thought it could be related to #2658, but I have plotly 4.11.1 installed and I tried to increase the difference between Start/Stop to more than 10 seconds. I also tried @ennosigaeus suggestion of converting to string, and I tried to convert to python datetime objects as well, nothing worked. This is the code I'm using to plot the chart: fig = px.timeline(
df,
x_start="Start",
x_end="Finish",
y='Task',
color="Resource",
hover_data={
'Start': '|%Y/%m/%d %H:%M:%S',
'Finish': '|%Y/%m/%d %H:%M:%S'
}
) |
Related to/duplicate of #2934 ... it seems like at the moment, using |
Could someone seeing this issue please post a self-contained, reproducible example of this issue happening with some other function than |
OK, I've got a replicable test case which #3018 resolves: import plotly.express as px
import pandas as pd
df = px.data.stocks()
df["date"] = pd.to_datetime(df["date"])
fig = px.scatter(df, x="date", y="GOOG", hover_data=dict(date="|%Y"))
fig.show() Unfortunately, if the column being formatted is not one of x/y/z/base, #3018 doesn't resolve it: import plotly.express as px
import pandas as pd
df = px.data.stocks()
df["date"] = pd.to_datetime(df["date"])
df["other_date"] = df["date"]
fig = px.scatter(df, x="date", y="GOOG", hover_data=dict(other_date="|%Y"))
fig.show() This seems to be because |
@nicolaskruchten, I don't remember the specifics off the top of my head, but I did run into a few limitation with |
That would be an unexpected bonus :) |
No such luck. I think it's something special about how |
Ok, I don't have any other ideas off the top of my head. Are things already messed up in |
Yep. I think that whatever logic is used to manage Pandas date columns just isn't applying to |
Maybe here https://github.com/plotly/plotly.py/blob/master/packages/python/plotly/_plotly_utils/basevalidators.py#L383 we're not handling the shape of |
Simple example to show the problem: import plotly.graph_objects as go
import pandas as pd
df = pd.DataFrame(dict(t=["2010-01-01", "2010-01-02"]))
df["t"] = pd.to_datetime(df["t"])
print(go.Figure(go.Scatter(x=df["t"], customdata=df[["t"]]), layout=dict(template="none")).to_json())
print(go.Figure(go.Scatter(x=df["t"], customdata=df["t"]), layout=dict(template="none")).to_json()) the first line is what PX does, the second line shows that |
Thanks for the fix @nicolaskruchten and @jonmmease . Your help is appreciated! |
I noticed that DateTime objects in Python do not render correctly in the plot tooltips when they are included as
hover_data
arguments in plotly express functions. See example below.Desired behavior would be the way that IPython renders the DateTime objects using the
display
function. See below:The exact datatype of the Timestamp Series is
dtype('<M8[ns]')
, which is a numpy specific dtype.The text was updated successfully, but these errors were encountered: