this is my code
Rate = ['Total',"10 ","20 ","30 ","40 ","50 ","60 "]
NetAmount = [4,2,5,-4,8,-6,7][::-1]
df = pd.DataFrame(NetAmount,index=Rate,columns=['Value'])
fig,ax = plt.subplots()
df.plot(ax=ax,kind='barh',legend=None,title='Value')
ax.set_ylabel('Rate',fontsize=12)
I want labels of my y axis above x=0 not on the extreme left. How do I do that?
CodePudding user response:
You could move the left spine and hide the top and right ones:
ax.spines['left'].set_position(('data', 0))
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
# move back the ylabel to the left (optional)
ax.yaxis.set_label_coords(0, 0.5)
output:
If you want to keep the frame, duplicate the spine:
from copy import copy
ax.spines['left_copy'] = copy(ax.spines['left'])
ax.spines['left'].set_position(('data', 0))
ax.yaxis.set_label_coords(0, 0.5)
output: