How do I fix the overlapping dates?

Viewed 65

I want to solve the problem of overlapping dates under the chart. I think it's because there are too many dates displayed. Please let me know?

df['Close'] = df['Close'].astype(float)
plt.figure(figsize=(20,7))
plt.plot(df['Date'].values, df['Close'].values, label = 'Bitcoin Stock Price', color = 'red')
plt.xticks(np.arange(100,df.shape[0],200))
plt.xlabel('Date')
plt.ylabel('Close ($)')
plt.legend()
plt.show()

current plot

1 Answers

Convert the Date column to_datetime() before plotting; then matplotlib will handle the date formatting automatically:

df['Date'] = pd.to_datetime(df['Date'])
plt.plot(...)
Related