Matplotlib主次记号不在syn中

2024-04-23 18:27:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码如下所示:

fig, ax = plt.subplots(figsize=(8,5))
hours = dates.HourLocator(interval = 2)
h_fmt = dates.DateFormatter('%H:%M')

ax.plot(times, y_values)

xmin, xmax = plt.xlim()
xmin_0 = math.ceil(xmin) # Rounding up to start of day
ax.set_xlim(xmin_0,)

ax.xaxis.set_major_locator(hours)
ax.xaxis.set_major_formatter(h_fmt)
ax.xaxis.set_minor_locator(mdates.MinuteLocator(interval=20))

问题是,如图所示,大x记号和小x记号似乎没有对齐。你知道吗

我试过将x轴设置为从0开始,但没有自动执行,但没有效果。你知道吗

“times”是一个datetimes数组,格式为:“2018-02-04 00:00:00”

enter image description here


Tags: 代码pltaxdatesxminintervalsettimes