Change number of ticks in Date column

Viewed 76

What can I add to this code to change the number of ticks on the x-axis which represents Date to let it appear?

I just want few ticks

plt.figure(figsize= (10,5))

plt.plot(AAPL['Date'], AAPL['Adj Close'], label = 'Apple')

plt.plot(AMZN['Date'], AMZN['Adj Close'], label = 'Amazon')

plt.plot(GOOG['Date'], GOOG['Adj Close'], label = 'Google')

plt.plot(MSFT['Date'], MSFT['Adj Close'], label = 'Microsoft')


plt.legend()
plt.show()

enter image description here

2 Answers

Try this:

start, end = plt.get_xlim()
plt.xaxis.set_ticks(np.arange(start, end, stepsize))

edit: oops. looks like you might need to call get_xlim() on the axes.

axes = plt.gca() #gca = get current axes
start, end = axes.get_xlim()
Related