start a line plot away from y axis

360 views Asked by At

code is as below

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')

Running this code I am getting a plot as below

line plot

Here the plot is starting from y-axis how to push it little right

1

There are 1 answers

0
MarianD On

In your command

ax.set(xlabel="X-axis",ylabel="Y-axis",title="2d line plot",xlim=(0,8),ylim=(2000,15000))

change the first number in parameter xlim=(0,8) to some negative value; use e.g. xlim=(-.5,8):

ax.set(xlabel="X-axis",ylabel="Y-axis",title="2d line plot",xlim=(-.5,8),ylim=(2000,15000))

enter image description here