If you submit two arrays as arguments, it is assumed that they are x-coordinates and y-coordinates respectively. If you use only one array, these values will be used as y-coordinates and the x-coordinates will be [0, 1, 2, ...].
You have multiple options to plot more than one function.
You can submit x and y values for each graph you want to plot:
Note that the length of the arrays must be equal, or you'll run into e.g.:
That's why I prefer method 2: calling plot() separately for each line:
You have multiple options to plot more than one function.
You can submit x and y values for each graph you want to plot:
x_list = range(6) plt.plot(x_list, forecast, x_list, train_W, x_list, train_Z)The colors of the lines will be different by default, but if you want to set them manually you could do that like this:
plt.plot(x_list, forecast, 'r-.', x_list, train_W, 'bx', x_list, train_Z, 'y')But imho this code is not very easy to read. (note that 'r-.' means a dashed red line, 'bx' means blue 'x' markers with no line)
Note that the length of the arrays must be equal, or you'll run into e.g.:
Error:ValueError: x and y must have same first dimension, but have shapes (6,) and (5,)
Also, if you want to apply other keyword arguments to the plot they'll apply to each of those lines:plt.plot(x_list, forecast, x_list, train_W, x_list, train_Z, label='test') plt.legend() plt.show()Each line in this plot will have the same entry in the in the legend.
That's why I prefer method 2: calling plot() separately for each line:
plt.plot(forecast) plt.plot(train_Z) plt.show()or with x-values explicitly included:
plt.plot(x_list, forecast) plt.plot(x_list, train_Z) plt.show()or with different keyword arguments for each line
plt.plot(x_list, forecast, label='forecast') plt.plot(x_list, train_Z, label='train Z') plt.legend() plt.show()You can find more info about how to use arguments for plot here: https://matplotlib.org/api/pyplot_api.ht...yplot.plot