我需要绘制时间序列数据。下面是示例代码:如何沿x轴移动图形?
ax2 = pyplot.subplot(212)
true_targets = pyplot.plot(test_y[:, 0, :])
guessed_targets = pyplot.plot(test_y_hat[:, 0, :], linestyle='--')
并可以产生下列图表:
欲图形以沿着x轴向右移动(从1而不是0开始) 。
我需要绘制时间序列数据。下面是示例代码:如何沿x轴移动图形?
ax2 = pyplot.subplot(212)
true_targets = pyplot.plot(test_y[:, 0, :])
guessed_targets = pyplot.plot(test_y_hat[:, 0, :], linestyle='--')
并可以产生下列图表:
欲图形以沿着x轴向右移动(从1而不是0开始) 。
只是使用plot
与指定x值的矢量:代替
plot(x_values, y_values, linestyles etc)
只是
plot(y_values, linestyles etc)
当然,x_values
和y_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)
。
也许我在这里误解的问题,但如果你只是想你的x轴在1而不是0开始(在不改变任何你的价值观),你可以设置x限制你的轴:
ax2.set_xlim(1,len(test_y_hat))
你可以有一些条件逻辑来设置x轴的上限,而不是像上面那样获得矢量的长度