I need to plot time-series data. Here is the sample code:
ax2 = pyplot.subplot(212)
true_targets = pyplot.plot(test_y[:, 0, :])
guessed_targets = pyplot.plot(test_y_hat[:, 0, :], linestyle='--')
And it produces the following graph:

I want to shift the graph to the right along x-axis (start from 1 instead of 0).
just use plot with a vector that specifies the x values:
plot(x_values, y_values, linestyles etc)
instead of just
plot(y_values, linestyles etc)
Of course, x_values and y_values need to have the same length. You can easily ensure that by doing something like
plot(range(1,1+len(y_values)), y_values, linestyles etc)
I generally often find myself in a situation where integers don't cut it as x coordinates, so I often use numpy (import numpy) and do
x_values = numpy.linspace(lower, upper, n_points)
and n_points is usually just len(y_values).
Maybe I'm misunderstanding the problem here, but if you just want your xaxis to start at 1 instead of 0 (without changing any of your values) you can just set the x limit on your axes:
ax2.set_xlim(1,len(test_y_hat))
You can have some conditional logic to set the upper limit on the x axis instead of getting the length of the vector like I did above
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With