matplotlib 添加偏移量

为了便于控制,咱们的偏移量其实是对横坐标做一个调整:对每个x值都增加一个固定的值

示例

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams['font.family'] = ['Heiti TC']

if __name__ == '__main__':
    pass
    x = np.array(list(range(100)))
    y = np.random.randint(0, 10, size=(100))
    # x添加偏移量
    det_x = np.random.random()
    # 开始绘图
    plt.figure(figsize=(14, 10))
    plt.plot(x, y)
    plt.plot(x + det_x, y)
    plt.show()

效果图:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_35757704/article/details/121664444