1

I have the following code:

pyplot.plot(np.arange(1,39) , train, color = "blue")
pyplot.plot(np.arange(39,60), test, color = "red")
pyplot.show()

But I can not plot test as a continuation of train.

And I get this error:

ValueError: x and y must have same first dimension, but have shapes (21,) and (23, 1)
Dávid Kókai
  • 57
  • 1
  • 5

2 Answers2

1

It's not clear what you want, but if you need different axis in the same figure ("two plots") you should create subplots like this:

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(nrows=2,ncols=1)
ax1.plot(np.arange(1,39), train, color='blue')
ax2.plot(np.arange(39,60), test, color='red)

If you want two x-axis in the same plot take a look at this question

gmolnar
  • 108
  • 1
  • 6
1

well, you have to have train with the same size of np.arange(1,39), which has the size of (38,). The same way, you have to have test with the same size of np.arange(39,60), which has the size of (21,).

you probably have to change your second line of code to the following line of code:

pyplot.plot(np.arange(39,62).reshape(23, 1), test, color = "red")
Fatemeh Sangin
  • 558
  • 1
  • 4
  • 19