matplotlib / matplotlib/matplotlib

[Bug]: ConciseDateFormatter doesn't handle DST changes correctly

Đang mở
#29,160 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

topic: date handling
Ngôn ngữ chính
Python
Star
23.2k
Fork
8.5k
Merge trung bình
1 ngày 6 giờ
Pull request đã merge (30 ngày)
66

Mô tả

### Bug summary

When the time series to plot has a day light saving change and the time zone of data changes, the ticker labels formatted incorrectly. It seems to format time zone part instead of the correct base, in this example the day.

### Code for reproduction

```Python
import datetime

import matplotlib.pyplot as plt
import numpy as np

import matplotlib.dates as mdates
from zoneinfo import ZoneInfo

base = datetime.datetime(2005, 2, 1)
dates = [base + datetime.timedelta(hours=(2 * i)) for i in range(732)]
N = len(dates)
np.random.seed(19680801)
y = np.cumsum(np.random.randn(N))

fig, axs = plt.subplots(3, 1, layout='constrained', figsize=(6, 6))
lims = [(np.datetime64('2024-10-27'), np.datetime64('2024-11-10')),
(np.datetime64('2024-11-11'), np.datetime64('2024-11-22')),
(np.datetime64('2005-02-03 11:00'), np.datetime64('2005-02-04 13:20'))
]

fig, axs = plt.subplots(3, 1, layout='constrained', figsize=(6, 6))

for nn, ax in enumerate(axs):
# locator = mdates.AutoDateLocator()
locator = mdates.AutoDateLocator(tz=ZoneInfo("America/Los_Angeles"))
formatter = mdates.ConciseDateFormatter(locator)
formatter.formats = ['%y', # ticks are mostly years
'%b', # ticks are mostly months
'%d', # ticks are mostly days
'%H:%M', # hrs
'%H:%M', # min
'%S.%f', ] # secs
# these are mostly just the level above...
formatter.zero_formats = [''] + formatter.formats[:-1]
# ...except for ticks that are mostly hours, then it is nice to have
# month-day:
formatter.zero_formats[3] = '%d-%b'

formatter.offset_formats = ['',
'%Y',
'%b %Y',
'%d %b %Y',
'%d %b %Y',
'%d %b %Y %H:%M', ]
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)

ax.plot(dates, y)
ax.set_xlim(lims[nn])
axs[0].set_title('Concise Date Formatter')

plt.show()
```

### Actual outcome

Screenshot 2024-11-20 at 4 19 38 PM

### Expected outcome

2nd graph of the same image shows the expected tick labels in the graph.

### Additional information

_No response_

### Operating system

_No response_

### Matplotlib Version

3.9.2

### Matplotlib Backend

macosx

### Python version

Python 3.11.6

### Jupyter version

_No response_

### Installation

pip

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách chạy bản tái hiện Python được cung cấp với matplotlib.dates.AutoDateLocator và ConciseDateFormatter, tập trung vào các biểu đồ bao gồm thời điểm chuyển sang giờ mùa hè. Theo dõi cách ConciseDateFormatter chọn các thành phần ngày tháng và thông tin múi giờ cho các nhãn tick. Hoàn thành khi các nhãn hiển thị đúng ngày cơ sở qua các thay đổi DST, đồng thời vẫn giữ đầu ra như mong đợi trong các biểu đồ khác.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.