I am trying to create a barplot, but I have a problem, the distance between the title and first bars, and also the distance between the last bars and X axis are to long, how can I reduce it? please take a look at the code that I have used, in blue is marked the distance that I want to reduce. Thanks for your help!!!
Regards, António Fernandes
import matplotlib.pyplot as plt;import seaborn as sns; import os;sns.set();import random
#defining font and color
font_color = '#525252';hfont = {'fontname':'Calibri'};facecolor = '#eaeaf2'
#create my dataset for the plot
LABELS =[] ;DATA_0 = [];DATA_1 = [];year=0
for i in range(40):
DATA_0.append(random.randint(0, 400))
DATA_1.append(random.randint(0, 400))
year+=1
LABELS.append("Label "+str(year))
# start my plot
fig, axes = plt.subplots(figsize=(10,17), facecolor=facecolor, ncols=2, sharey=True)
fig.tight_layout()
axes[0].barh(LABELS, DATA_0,height=0.8, align='center', color='#8AC847', zorder=10)
axes[1].barh(LABELS, DATA_1,height=0.8, align='center', color='#fd625e', zorder=10)
axes[0].invert_xaxis()
axes[0].set(yticks=LABELS, yticklabels=LABELS)
axes[0].yaxis.tick_left()
axes[0].set_title('Title 0', fontsize=18, pad=15)
axes[1].set_title('Title 1', fontsize=18, pad=15)
### format y axis
axes[0].tick_params(axis='y', colors='white') # tick color
axes[1].tick_params(axis='y', colors='white') # tick color
for label in (axes[0].get_xticklabels() + axes[0].get_yticklabels()):
label.set(fontsize=13, color=font_color, **hfont)
for label in (axes[1].get_xticklabels() + axes[1].get_yticklabels()):
label.set(fontsize=13, color=font_color, **hfont)
#upper and lower limits of x axis
axes[0].set_xlim(400, 0);axes[1].set_xlim(0, 400)
#show my probleem, gab between the first/last bar and the limits of the plot
plt.text(-200, 40, "
<=>",zorder=11,fontsize=20,color='blue',rotation="vertical");plt.text(-180, 40, "There is a
big gap",zorder=11,fontsize=20,color='blue');plt.text(50, 40, "
<=>",zorder=11,fontsize=20,color='blue',rotation="vertical");plt.text(-200, -2, "
<=>",zorder=11,fontsize=20,color='blue',rotation="vertical");plt.text(-180, -2, "There is a
big gap",zorder=11,fontsize=20,color='blue');plt.text(50, -2, "
<=>",zorder=11,fontsize=20,color='blue',rotation="vertical")
##final part to create the plot
plt.subplots_adjust(wspace=0, top=0.85, bottom=0.1, left=0.18, right=0.95)
path='C:/Users/acpf9/Desktop/TEST'
plt.savefig(path+'.jpg',bbox_inches='tight')
os.startfile(path+'.jpg')