Code: data_ori is the entire univariate one-dimensional data set. First, construct the shape so that the data structure data_ori to be drawn by train and test are consistent, and then fill in the nan value, and finally fill in the valid data.
import matplotlib.pyplot as plt
import pandas as pd
split_ratio = 100
test_num = 140 #取140个数据做测试
data_ori = selected_dataset[0:test_num]
train_data = data_ori.iloc[0:split_ratio]#除了最后一列不要,代码还可以更加完善可读性高
test_data = data_ori.iloc[split_ratio+20:test_num]#这个20是为了演示下方图蓝色部分
trainPredictPlot = numpy.empty_like(data_ori)
trainPredictPlot[:] = numpy.nan
trainPredictPlot[:split_ratio] = train_data
testPredictPlot = numpy.empty_like(data_ori)
testPredictPlot[:] = numpy.nan
testPredictPlot[split_ratio+20:test_num] = test_data
plt.plot(data_ori)#全部
plt.plot(trainPredictPlot)#训练预测
plt.plot(testPredictPlot)#测试预测
plt.show()
data_ori graphics
Train_predict and test_predict graph
data_ori and Train_predict and test_predict graphs, the first segment is train_predict, the second segment is data_ori, and the third segment is test_predict