在绘制时间序列时,我观察到一种不寻常的行为,最终导致无法格式化绘图的xticks.似乎pandas在内部尝试将索引转换为PeriodIndex,但显然只有在时间戳值相等的情况下才能成功.如果它们间隔不均匀(或者 - 奇怪的是 - 如果它们间隔均匀但有时区感知),索引仍然是DatetimeIndex.后一种情况按预期工作.我可以设置DateFormatter和Locators.但是,如果索引在绘图之前被逐步转换为PeriodIndex,则生成的plott的x轴似乎搞砸了.
这是一个重现问题的示例.
from pandas import Series, DataFrame
import pandas as pd
from datetime import datetime
import pytz
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
idx1 = np.array([datetime(2014, 1, 16, 0),
datetime(2014, 1, 16, 5),
datetime(2014, 1, 16, 10),
datetime(2014, 1, 16, 15),
datetime(2014, 1, 16, 20),
datetime(2014, 1, 17, 1)])
idx2 = np.array([datetime(2014, 1, 16, 0),
datetime(2014, 1, 16, 5),
datetime(2014, 1, 16, 10),
datetime(2014, 1, 16, 15),
datetime(2014, 1, 16, …
Run Code Online (Sandbox Code Playgroud)