与熊猫一起使用DateFormatter时出现年错误

时间:2019-02-22 17:42:02

标签: python pandas matplotlib

我遇到与this类似的问题,但是那篇文章没有提供一个最小的例子。有人有建议吗?

我衷心希望答案不会是“升级到matplotlib 3”,因为iris程序包目前不支持该功能,并且iris对我的工作非常有用。

data.txt:

# make one iterator that goes one ahead and wraps around at the end
next_ones = itertools.cycle(vertices)
next(next_ones)
for ((x1, y1), (x2, y2)) in zip(vertices, next_ones):
    # unchecked...
    if (((y1 > testy) != (y2 > testy)) 
            and (testx < (x2 - x1) * (testy - y1) / (y2-y1 + x1))):
       c = not c

代码:

01-01-2019,00:00:03,334
01-01-2019,00:00:13,314
01-01-2019,00:00:23,295
01-01-2019,00:00:33,280
01-01-2019,00:00:43,310
01-01-2019,00:00:53,300
01-01-2019,00:01:03,310

第一个show语句给出了这一点,

From the first show

第二个抛出了美丽,

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as md

data = pd.read_csv(
    "data.txt", infer_datetime_format=True,
    dayfirst=True, parse_dates=[["date", "time"]],
    index_col="date_time",
    names=("date", "time", "wind")
)

ax = plt.axes()
data["wind"].plot(ax=ax)
plt.show()

ax = plt.axes()
data["wind"].plot(ax=ax)
ax.xaxis.set_major_formatter(md.DateFormatter('%Y'))
plt.show()

0 个答案:

没有答案