-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Timezone parsing issue with plotly.py JSON serialization #209
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
Comments
@actioncrypto , thanks for reporting. Is the time correct in UTC, or completely off? |
As far as plot.ly seems to be concerned, all time is UTC and that's final. In the example above, if you run it, you will see that the |
Ok, on the same page now. You're right, there's not much to be done from the python-api side of things right now. I'm looking into it. I'll get back to you when I have more information. |
Hi, can I check if there's more information on this? Thanks much! |
@huixian no more information at the moment, the python client continues to force things into being UTC. Apologies for the inconvenience for now. |
@theengineear no worries; will work around it. :) thanks much for replying. |
Has there been any update for this forced UTC conversion on the x-axis request? Barring a bug-fix patch, is there anything we can do to hack the x-axis into local timezone? |
Any updates on that`?
|
A workaround for this: to convert the datetime from aware datetime to naive datetime, by removing the If you're using pandas, you can use print df.index[0]
# 2017-02-06 21:00:00+08:00
df_index = df.index.tz_localize(None)
print df_index[0]
# 2017-02-06 21:00:00 |
I would also like to give plotly tz-aware datetimes and have them shown in the provided timezone. Maybe have an API-configurable option to select the viewing timezone? |
It looks like conversion to utc timezone happens here. I have comment this conversion and got normal looking local time with proper timezone for x-axis. |
Is there a workaround for this if I'm not using pandas? |
I tried what @pohmelie mentioned and that worked for me. I did notice that when i used cufflinks to create charts the timezone is honored, when i use the graph object it is not. Its seems as though plotly can check if a TZ is set and if so then ignore otherwise convert to UTC. |
Why does Plotly convert the datetime to UTC at all, and not handle the timezone as it was set by the user? Is this somehow internally important? |
This is a solution to McKlevin's idea for those not using pandas. I used the localize function from pytz and solved the plotly hours conversion problem. |
the fix is to localize to UTC, convert to your user's tz, then remove the tz_info worked for me something like: Side note: |
For financial timeseries data looking at plots in local timezone is very critical. |
For a quick temp fix, the suggestion from @pohmelie in #209 (comment) works great. The code has changed slightly, but commenting out the following should get the job done: Lines 294 to 306 in 663a386
Alternatively, after having manipulated the datetime objects however needed, they can be converted to strings, and then passed to graphs as data: https://stackoverflow.com/a/54638376/7432972 |
Checking in on this. When I make a plot with a tz-aware datetime (DateTimeIndex with a timezone in pandas) the correct times are displayed. When I export to html or an image, the timezone is SILENTLY converted to UTC. I'm sure the workaround provided works, but is someone still working on this? |
I'm having issues with this as well in Jupyter Lab. If I create a plot with a tz-aware datetime, the plot will display in local time if I simply call the name of the figure object at the bottom of a code cell. But if I use |
See my comment for an ugly hack. @shkramer13
…________________________________
From: shkramer13 <[email protected]>
Sent: Tuesday, March 26, 2019 1:17:56 PM
To: plotly/plotly.py
Cc: Beane, Jermell [COMRES/WR/US]; Comment
Subject: [EXTERNAL] Re: [plotly/plotly.py] Timezone parsing issue with python plot.ly API (#209)
I'm having issues with this as well in Jupyter Lab. If I create a plot with a tz-aware datetime, the plot will display in local time if I simply call the name of the figure object at the bottom of a code cell. But if I use iplot(fig) instead of fig, the figure displays in UTC.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub [github.com]<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_plotly_plotly.py_issues_209-23issuecomment-2D476782799&d=DwMFaQ&c=jOURTkCZzT8tVB5xPEYIm3YJGoxoTaQsQPzPKJGaWbo&r=KVI6-geanVBy3OgJ41M5unmKFYQlg1Fy7gYHnQgR2Q4&m=AB_wO6FO6vKzNZs-NMO0lkaxnjmtPwk9GHgMCfMKwo0&s=V3hiEtAw-t61SzJjM1DIrTaelWoWcr3mw6BBqw3QuF8&e=>, or mute the thread [github.com]<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_Amht6yp7TrRQuP5LczvZ9E4TeAlMFzs3ks5vamRUgaJpZM4D-2DH1F&d=DwMFaQ&c=jOURTkCZzT8tVB5xPEYIm3YJGoxoTaQsQPzPKJGaWbo&r=KVI6-geanVBy3OgJ41M5unmKFYQlg1Fy7gYHnQgR2Q4&m=AB_wO6FO6vKzNZs-NMO0lkaxnjmtPwk9GHgMCfMKwo0&s=aogUGZWoF1XDl9ur2TLDDI8SlkIR-aZGezJrsBkX1N4&e=>.
|
Hi all, I haven't really dug into this yet but it's definitely important and something that we plan to take care of as a part of version 4. Thanks for helping each other out with workarounds in the meantime! |
See version 4 proposal at #1581. For dev-build installation instructions, see #1581 (comment). |
Hello,
This is a code snippet that shows how even when explicitly defining timezones, and stripping out any possible confusion, plot.ly will refuse to display the X axis in the local timezone, instead converting and showing UTC only.
My working code is slightly different, but the incorrect end behavior is the same in this case as well when originating from strings and simple
DataFrames
inspecting the
fig
immediately before being called to draw graph indeed shows the correctUS/Eastern
timezone, which happens as expected when thex
value of thetrace
is defined.The text was updated successfully, but these errors were encountered: