I was wondering how I can adjust my dates here so that they're smaller and fit better on the output.I've tried rotating but they just seem like they're floating aimlessly below the chart. Also Id like to make the legend just either have y_pred
and y_test
one time somewhere where it doesn't overlap my charts.
These subplots are added via a loop and it wont always be the same number of loops.
For reference no_splits will determines how many loops are run via the TimeSeriesSplit
method. Ive removed a lot of the irrelevant code so it's easier to follow
Here is my code:
fig = plt.figure()
tscv = TimeSeriesSplit(n_splits=self.no_splits)
for train_index, test_index in tqdm(tscv.split(X)):
X_train, X_test = X.iloc[train_index], X.iloc[test_index]
y_train, y_test = y.iloc[train_index], y.iloc[test_index]
# predict y values
y_pred = self.regressor.predict(X_test)
# plot y_pred vs y_test
y_df = pd.DataFrame(index= X_test_index)
y_pred = y_pred.reshape(len(y_pred), )
y_test = y_test.reshape(len(y_test), )
y_df['y_pred'] = y_pred
y_df['y_test'] = y_test
ax = fig.add_subplot(int(sqrt(self.no_splits)), int(sqrt(self.no_splits)+1), i)
y_df.plot(title = 'Split{}'.format(i), ax=ax, legend=False)
ax.tick_params(axis='x', rotation=45)
plt.figlegend()
plt.subplots_adjust(wspace=0, hspace=0)
plt.show()