如何用不同的 X 轴绘制 python 中的两个值?
How to plot two values in python with different X axis?
我有以下代码:
pyplot.plot(np.arange(1,39) , train, color = "blue")
pyplot.plot(np.arange(39,60), test, color = "red")
pyplot.show()
但我不能将测试作为火车的延续。
我收到这个错误:
ValueError: x and y must have same first dimension, but have shapes (21,) and (23, 1)
不清楚你想要什么,但如果你需要在同一个图中使用不同的轴(“两个图”),你应该像这样创建子图:
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)
如果你想在同一个图中使用两个 x 轴,请看一下这个 question
好吧,你必须拥有大小与 np.arange(1,39) 相同的火车,其大小为 (38,)。同样,您必须使用相同大小的 np.arange(39,60) 进行测试,其大小为 (21,).
您可能需要将第二行代码更改为以下代码行:
pyplot.plot(np.arange(39,62).reshape(23, 1), test, color = "red")
我有以下代码:
pyplot.plot(np.arange(1,39) , train, color = "blue")
pyplot.plot(np.arange(39,60), test, color = "red")
pyplot.show()
但我不能将测试作为火车的延续。
我收到这个错误:
ValueError: x and y must have same first dimension, but have shapes (21,) and (23, 1)
不清楚你想要什么,但如果你需要在同一个图中使用不同的轴(“两个图”),你应该像这样创建子图:
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)
如果你想在同一个图中使用两个 x 轴,请看一下这个 question
好吧,你必须拥有大小与 np.arange(1,39) 相同的火车,其大小为 (38,)。同样,您必须使用相同大小的 np.arange(39,60) 进行测试,其大小为 (21,).
您可能需要将第二行代码更改为以下代码行:
pyplot.plot(np.arange(39,62).reshape(23, 1), test, color = "red")