Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

python - x-axis ticks not appearing in matplotlib graph?

I have a dataframe with a column 'Date' and a column 'Close Price' for the S&P500 from 2010 to 2017. The column date has format YYYY:MM:DD.

I am trying to make a close price vs date graph in matplotlib. The problem is that there are no default x-axis ticks for the date, there is just a black line. I guess the reason is that there are too many dates. Is it possible to make at least a few dates to show? Such as the 1st of each year? Thank you so much for your help in advance!

fig = plt.figure()
ax = plt.axes()
x = df['Date']
y = df['Close']
ax.plot(x,y,label='S&P500')
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels)

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...