Python 3.x 从远离y轴的位置开始绘制线图

Python 3.x 从远离y轴的位置开始绘制线图,python-3.x,matplotlib,line-plot,Python 3.x,Matplotlib,Line Plot,代码如下 import pandas as pd import matplotlib.pyplot as plt dates = ['2010-11', '2011-12', '2012-13', '2013-14', '2014-15', '2015-16', '2016-17'] steps = [9000, 9500.756, 9800.859, 10000.262, 9800.972, 10500.058, 11300.703] fig=plt.figure(figsize=(10,8)

代码如下

import pandas as pd
import matplotlib.pyplot as plt
dates = ['2010-11', '2011-12', '2012-13', '2013-14', '2014-15', '2015-16', '2016-17']
steps = [9000, 9500.756, 9800.859, 10000.262, 9800.972, 10500.058, 11300.703]
fig=plt.figure(figsize=(10,8))
ax=fig.add_subplot(111)
ax.set(xlabel="X-axis",ylabel="Y-axis",title="2d line plot",xlim=(0,8),ylim=(2000,15000))
ax.plot(dates,steps, color='red',linewidth=2,marker='o',label='LPG')
plt.show()
plt.close('all')
运行这段代码,我得到了如下图

这里的绘图是从y轴开始的,如何在命令中将其稍微向右推

ax.set(xlabel="X-axis",ylabel="Y-axis",title="2d line plot",xlim=(0,8),ylim=(2000,15000))
将参数
xlim=(0,8)
中的第一个数字更改为某个负值;使用例如
xlim=(.5,8)


您可以查看SETxticks和SETxticklabels,这里的答案是:
ax.set_xlim([datetime.date(2014,1,26),datetime.date(2014,2,1)])
ax.set(xlabel="X-axis",ylabel="Y-axis",title="2d line plot",xlim=(-.5,8),ylim=(2000,15000))