Skip to content

Commit c83aa59

Browse files
Merge pull request #19 from alexanderthclark/complete-dates-timezones
Complete time zone handling section
2 parents bfdbc85 + 64a4246 commit c83aa59

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎tex/prose/dates.tex‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ \section{Plotting}
2323

2424
\subsection{Time Zone Handling}
2525

26-
%\code{plot_date()} also plots the dates according to a default UTC timezone, sometimes converting dates given in a different timezone. This can be modified with the \code{tz} parameter, but this requires covering
26+
Matplotlib's date converters, locators, and formatters are time-zone aware. If no time zone is specified, Matplotlib uses \code{rcParams['timezone']}, which is \code{'UTC'} by default. You can choose the time zone used for tick labels by passing an IANA time-zone name to a formatter, as in \code{mdates.DateFormatter('\%H:\%M \%Z', tz = 'America/New\_York')}. The underlying observations do not move; only their displayed clock times change.
2727

28+
It is important to distinguish conversion from localization. A time-zone-aware timestamp identifies an unambiguous instant and can be converted for different audiences while a naive timestamp contains no such information. With pandas, \code{tz\_localize()} attaches a time zone to naive dates, while \code{tz\_convert()} converts dates that are already time-zone aware. Localize only when you know which time zone the recorded clock times represent. Otherwise, the same numbers can be assigned to the wrong instant.
2829

29-
For a deeper knowledge, see the \code{datetime.tzinfo} class and the \code{pytz} library. TK
30+
Named zones are better than fixed offsets because their rules account for daylight-saving transitions. Python's standard-library \link{https://docs.python.org/3/library/zoneinfo.html}{\code{zoneinfo}} module supplies \code{tzinfo} objects for these zones. For plotting, a zone name or \code{tzinfo} object can be passed to Matplotlib's \link{https://matplotlib.org/stable/api/dates_api.html}{date locators and formatters}. Best practice is to store an unambiguous time, commonly in UTC, and convert it only when choosing how the audience should read the axis.
3031

3132
\section{Ticks and Formatting}
3233

0 commit comments

Comments
 (0)