Python 如何将x轴上的样本更改为折叠?

Python 如何将x轴上的样本更改为折叠?,python,matplotlib,plot,time-series,Python,Matplotlib,Plot,Time Series,对于一个项目,我在时间序列上做了10倍的交叉验证。为了可视化我的结果,我创建了如下图: 为了更好地理解我的图,我宁愿在我的x轴上有褶皱(1-10),而不是样本 由于我使用时间序列数据,我的10倍交叉验证具有以下结构: 第0列-测试1 第1列-测试2 第1,2列-测试3 第1、2、3列-Tet 4 第1、2、3、4、5、6、7、8、9列-测试10 我的眼睛应该是这样的: 情节应该是什么样子] 这可能吗?如果可能,如何实现 这是我的代码: tscv = TimeSeriesSplit(n_s

对于一个项目,我在时间序列上做了10倍的交叉验证。为了可视化我的结果,我创建了如下图:

为了更好地理解我的图,我宁愿在我的x轴上有褶皱(1-10),而不是样本

由于我使用时间序列数据,我的10倍交叉验证具有以下结构:

  • 第0列-测试1
  • 第1列-测试2
  • 第1,2列-测试3
  • 第1、2、3列-Tet 4
  • 第1、2、3、4、5、6、7、8、9列-测试10
我的眼睛应该是这样的:

情节应该是什么样子]

这可能吗?如果可能,如何实现

这是我的代码:

tscv = TimeSeriesSplit(n_splits=10)
print(tscv)  

X = mergedf['AnzahlTweets']
y = mergedf['Kurs']

X=X.values.reshape(-1,1)
y=y.values.reshape(-1,1)

linreg=LinearRegression()
rmse=[]
prediction=np.zeros(y.shape)
for train_index, test_index in tscv.split(X):
    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = y[train_index], y[test_index]
    linreg.fit(X_train,y_train)
    y_pred=linreg.predict(X_test)
    prediction[test_index]=y_pred
    rmse.append(np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
    print('RMSE: %.10f' % np.sqrt(metrics.mean_squared_error(y_test, y_pred)))

pl.plot(y,label='Actual')
pl.plot(prediction, color='red',label='Predicted',)
pl.ylabel('Price')
pl.xlabel('Sample')
pl.legend()
pl.show()
提前谢谢


谢谢你提到一个现存的问题。这有助于解决我的一部分问题。另一部分是是否可以将x轴上的“样本”更改为“折叠”,以便将我的绘图分成10个折叠。

在这种情况下,只需使用
pl.gca().xaxis.grid(True)
谢谢!但这只是我问题的一部分。另一个更重要的部分是:如何将x轴上的样本更改为折叠?似乎“折叠”是指标签。我添加了另一个用于更改x标签的副本。