Pandas: Timezones for PeriodIndex

Created on 23 Oct 2012  路  9Comments  路  Source: pandas-dev/pandas

Most helpful comment

@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()

All 9 comments

xref: #2232

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

these r not supported

same issue, what's not supported?

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

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.

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.

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

@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()
Was this page helpful?
0 / 5 - 0 ratings