我需要繪製時間序列數據。下面是示例代碼:如何沿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軸的上限,而不是像上面那樣獲得矢量的長度