gpt4 book ai didi

python - 如何沿 x 轴移动图形?

转载 作者:太空狗 更新时间:2023-10-29 22:15:35 25 4
gpt4 key购买 nike

我需要绘制时间序列数据。这是示例代码:

ax2 = pyplot.subplot(212)
true_targets = pyplot.plot(test_y[:, 0, :])
guessed_targets = pyplot.plot(test_y_hat[:, 0, :], linestyle='--')

它会生成如下图表:

plot as I have it now

我想将图形沿 x 轴向右移动(从 1 而不是 0 开始)。

最佳答案

只需将 plot 与指定 x 值的向量一起使用:

plot(x_values, y_values, linestyles etc)

不仅仅是

plot(y_values, linestyles etc)

当然,x_valuesy_values 需要有相同的长度。你可以很容易地确保通过做类似的事情

plot(range(1,1+len(y_values)), y_values, linestyles etc)

我一般经常发现自己处在一个整数不切它为x坐标的情况,所以我经常使用numpy(import numpy)并做

x_values = numpy.linspace(lower, upper, n_points)

n_points 通常只是 len(y_values)

关于python - 如何沿 x 轴移动图形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32434607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com