#coding: utf-8 import matplotlib.pyplot as plt import numpy as np h = 0.5 # case-3, Case-2, case-1, dummy x1 = np.array([2955,2455,2455,0]) #Headrace x2 = np.array([951,922,770,0]) #Penstock x3 = np.array([425,415,777,0]) #tailrace y = np.array([0.5,1.5,2.5,3]) fig=plt.figure(figsize=(8,5)) plt.barh(y, x1, color='red', alpha=0.5,height=h, label='Headrace', align="center") plt.barh(y, x2, color='yellow',alpha=0.5,height=h, left=x1, label='Penstock', align="center") plt.barh(y, x3, color='cyan', alpha=0.5,height=h, left=x1+x2, label='Tailrace', align="center") for x,yy in zip(x1,y): if yy<3: plt.text(x/2,yy,'{0:.0f}'.format(x), size=15, ha='center', va='center') for s,x,yy in zip(x1,x2,y): if yy<3: plt.text(s+x/2,yy,'{0:.0f}'.format(x), size=15, ha='center', va='center') for s1,s2,x,yy in zip(x1,x2,x3,y): if yy<3: plt.text(s1+s2+x/2,yy,'{0:.0f}'.format(x), size=15, ha='center', va='center') for s1,s2,s3,yy in zip(x1,x2,x3,y): if yy<3: plt.text(50+s1+s2+s3,yy,'{0:.0f}'.format(s1+s2+s3), size=15, ha='left', va='center') plt.legend(loc='upper center', ncol=3,shadow=True, prop={'size' : 15},handlelength=2,handleheight=0.8) plt.subplots_adjust(bottom=0.2) plt.xticks(range(0,6000,1000),fontsize=15) plt.yticks(y, ['Case-3','Case-2','Case-1',''],fontsize=15) plt.xlabel('Length (m)',fontsize=15) plt.title('Comparison of Waterway Length',fontsize=20) fnameF = "fig_bar2.png" plt.savefig(fnameF) plt.show()