Matplotlib X轴DateTime-收集数据

问题描述 投票:0回答:2

我像这样用matplotlib进行绘图:

    # axis is a figure.subplot 
    axis.plot(df["DateTime"], df["yvalues"]) 
    axis.xaxis.set_major_formatter(mdates.DateFormatter('%d-%m %H:%M'))

结果像Graph

但是我想用正确的x轴刻度仔细查看数据。

python matplotlib plot
2个回答
0
投票

您可以尝试

#ticks option takes a list of x-axis tick locations.
tick_vals = ['2020-02-01','2020-03-01','2020-04-01']

#minor option takes Boolean that sets major ticks if False, sets Minor if True (False is default)
minor_option = False : bool, optional

import numpy as np

axes.set_xticks(ticks = tick_vals, minor=minor_option)

0
投票

如果您设置:

    axes.xaxis.set_major_locator(ticker.AutoLocator())
    axes.xaxis.set_minor_locator(ticker.AutoMinorLocator())

它将正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.