首页 > 解决方案 > 跳过图表python的x轴的间隔期

问题描述

我想自定义 pyplot 折线图的 x 轴。基本上,我有没有价值的时期,所以我想跳过这些时期。

示例图像

数据示例:

X 是的
以前的 2021-5-10 14:58 100.520
以前的 2021-5-10 14:59 100.500
红点 2021-5-10 15:00 100.550
绿点 2021-5-11 9:00 100.490
2021-5-11 9:01 100.650
2021-5-11 9:02 100.480
def chartValueTimeLine(time_series, value_series, line_color='blue', time_label='date', value_label='y_label', alpha_value=0.35, title='chart1'):
    fig = plt.figure(figsize=(12.5, 7), num=title)
    fig.subplots_adjust(bottom=0.2)
    plt.plot(time_series, value_series, label=value_label, color = line_color, alpha=alpha_value)
    plt.title(title)
    plt.xticks(rotation=45)
    plt.xlabel(time_label)
    plt.ylabel(value_label)
    plt.legend(loc='upper left')

我希望绿色点直接出现在 x 轴上的红色点之后。有谁知道如何做到这一点?

谢谢

标签: pythonmatplotlibcharts

解决方案


推荐阅读