你好 . 我现在正在绘制年份和数字字典数据的折线图 . 当我尝试使用matplotlib.pyplot绘制折线图时,其轴连续固定为0 .
例如,我想从dictonary( year_counts= {'2013':7, '2014':20, '2015':10, '2016':37, '2017':1} )绘制图形 . 但它的轴从0开始并增加1.即使我设置了x限制,plt.xlim(xmin = int(years [0]))或plt . axis([int(years [0]),int(years [-1]),0,max(book_counts)])它不起作用 .
我怎样才能在2013年开始x轴?
这是我使用的代码
year_counts= {'2013':7, '2014':20, '2015':10, '2016':37, '2017':1}
years = sorted(year_counts)
book_counts = [year_counts[year] for year in years]
plt.plot(years, book_counts)
plt.xlim(xmin=int(years[0])) # didn't work
plt.axis([int(years[0]), int(years[-1]), 0, max(book_counts)]) # didn't work
plt.show()
1 回答
您的轴实际上从2013年开始,如图所示
0 + 2.013e3
.为了摆脱这种偏移,请使用