2017-01-16 99 views
0

enter image description here如何将plt.plot x轴从0更改为实际值?

你好。我现在正在绘制年线和数字字典数据的线形图。 当我试图通过使用matplotlib.pyplot绘制线图,它的轴线连续地固定0

例如,我想从dictonary( year_counts = {“2013”​​绘制曲线图:7,“2014” :20,'2015':10,'2016':37,'2017':1}).But其坐标轴从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() 
+0

http://matplotlib.org/examples/pylab_examples/spine_placement_demo.html#pylab-examples-example-code-spine-placement-demo- py – wwii

+0

[Matplotlib中的中心原点]可能的重复(http://stackoverflow.com/questions/4694478/center-origin-in-matplotlib) – wwii

+0

好的我会检查它 – dizwe

回答

0

实际开始您的轴线在2013,这是0 + 2.013e3如图片可见的代码。

为了摆脱这种偏移,使用

ax = plt.gca() 
ax.ticklabel_format(useOffset=False) 
+0

谢谢我解决了它! – dizwe