X轴上的DateTime间隔图使用Matplotlib - Python

时间:2018-06-18 14:14:58

标签: python pandas matplotlib

我需要使用DateTime值来解决Xaxis中的拥塞问题。 有时我需要在10或15秒的时间间隔内绘制值,并且在这种情况下一切正常,但如果我有30或40秒,则X轴太拥挤。

我的代码:

def plot_1(data, par_time, par_yticks, par_ylabel, par_legend, par_st, par_et):
    data = data[(data['Time'] >= (par_st - timedelta(seconds=5))) & (data['Time'] <= par_et)]
    fig = plt.figure(figsize=(5.5, 3.5))
    ax1 = fig.add_subplot(111)
    plt.gca().set_color_cycle(['red', 'blue', 'green', 'brown'])
    ax1.plot(data[par_time], data[par_yticks], label=par_ylabel, marker='o', linewidth=2.0)
    plt.ylabel(par_ylabel)
    handles, labels = ax1.get_legend_handles_labels()
    ax1.legend(handles, par_legend, loc='upper center', bbox_to_anchor=(0.8, 1.15))
    ax1.grid('on')
    ax1.set_xlim(par_st, par_et)
    a = plt.savefig("graph.png")
    return a

如果需要数据示例,我会立即提供数据样本。

我现在得到的输出: enter image description here

有人将此问题标记为重复,但当我使用答案中的代码时,#34;复制&#34;问题,我收到了这样的错误:Locator attempting to generate 13875840 ticks from 736018.790394 to 737624.790278 exceeds Locator .MAXTICKS 我这是一个有用的答案我会用它,当然,不要浪费我的时间。

0 个答案:

没有答案