【发布时间】:2017-01-16 15:31:08
【问题描述】:
你好。我现在正在根据年份和数字字典数据绘制折线图。 当我尝试使用matplotlib.pyplot绘制折线图时,它的轴连续固定为0。
例如,我想从字典( 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()
【问题讨论】:
标签: python matplotlib