Skip to content

Timezones for PeriodIndex #2106

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

Closed
changhiskhan opened this issue Oct 23, 2012 · 10 comments
Closed

Timezones for PeriodIndex #2106

changhiskhan opened this issue Oct 23, 2012 · 10 comments
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type Timezones Timezone data dtype Visualization plotting

Comments

@changhiskhan
Copy link
Contributor

from SO: http://stackoverflow.com/questions/13030402/pandas-plot-function-ignores-timezone-of-timeseries

@changhiskhan
Copy link
Contributor Author

xref: #2232

@amelio-vazquez-reina
Copy link
Contributor

I am having the same problem here with the latest stable version of Pandas.

@jreback
Copy link
Contributor

jreback commented Jan 7, 2016

these r not supported

@vgoklani
Copy link

same issue, what's not supported?

@jreback jreback added the Period Period data type label May 28, 2016
@jreback
Copy link
Contributor

jreback commented May 28, 2016

Periods don't support timezone. Plotting needs to convert to a local tz before creating the periods.

@jreback jreback added the Visualization plotting label May 28, 2016
@emunsing
Copy link

As a workaround, you can remove the timezone info from the DateTimeIndex of the data which you're wishing to plot using .tz_localize(None) which will preserve the values but strip the timezone information. Matplotlib/pyplot will see these naive datetime values and assume that they are UTC, and will happily plot them with working x-axis ticks.

@jreback
Copy link
Contributor

jreback commented Oct 12, 2016

going to close this issue. This add needless complication because Periods can actually fall in more than 1 tz (e.g. on a DST change), when tz's are quite well supported on DTIs / Timestamps and the conversions are pretty straightforward.

@jreback jreback closed this as completed Oct 12, 2016
@stroobandt
Copy link

This StackExchange response leads to this issue.
Any kind of solution to this issue still seems to be appreciated.

@AvverbioPronome
Copy link

@stroobandt this is the solution I ended up using, I chose a timezone for the plot, and go with this:

import matplotlib.pytplot as plt, pandas as pd
df = pd.Dataframe(...)
fig, ax = plt.subplots()
df.plot(ax=ax)
import matplotlib.dates as mdates                                                                                   
from pytz import timezone                                                                                           
ax.xaxis.set_major_formatter(mdates.DateFormatter('%d/%m %H:%M', timezone('Europe/Amsterdam'))) 
fig.show()

@joooeey
Copy link
Contributor

joooeey commented Aug 5, 2022

I just tried to reproduce the issue described on StackOverflow and couldn't. Pandas plots the graph in whatever timezone the data is passed. That's exactly what a typical user would expect. The timezone is not mentioned anywhere on the plot.

Code from StackOverflow:

import numpy as np
import matplotlib.pyplot as plt
from pandas import DataFrame, date_range

rng = date_range('1/1/2011', periods=200, freq='S', tz="UTC")
data = DataFrame(np.random.randn(len(rng), 3), index=rng, columns=['A', 'B', 'C'])
data_cet = data.tz_convert("CET")

# plot with data in UTC timezone
fig, ax = plt.subplots()
data[["A", "B"]].plot(ax=ax, grid=True)
plt.show()

# plot with data in CET timezone, but the x-axis remains the same as above
fig, ax = plt.subplots()
data_cet[["A", "B"]].plot(ax=ax, grid=True)
plt.show()

UTC figure:

Figure_1

CET figure:

Figure_2

This is on Pandas 1.2.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type Timezones Timezone data dtype Visualization plotting
Projects
None yet
Development

No branches or pull requests

8 participants