I'm trying to plot price data with dates ax the xticks
. I've taken a look at this answer - "Changing the Tick Prequency" and this answer - "showing specific xtick on Matplotlib" but my problem seems to persist. Allow me to elaborate:
The data that I have looks something like this:
date Close
2017-05-10 0.12512
2017-05-11 0.12353
2017-05-12 -0.35235
.
.
.
2019-01-10 0.87890
It's a total of 608 entries, and the closing prices have all been scaled to be within (-1, 1).
The code that I wrote to make the plot is:
plt.plot(train['Close'], label='Training Data')
plt.Figure()
plt.plot(test['Close'], label='Test Data')
plt.grid(True)
plt.title("Closing Prices")
plt.ylabel('Price Scaled')
plt.xlabel('Time')
plt.legend()
plt.show()
which produces this image:
As you can see, the xtick
intervals are 100 in size and the graph starts at 0 and ends at 608. My question is: how do I format the graph so that the starting date (2017-05-10
) is at 0, and the xtick
prints only for each 100th tick? Also, I'm trying to get the 608th tick to show its date as well.