'How can I add space around the first/last bars in my seaborn barplot?

I am building a barplot using seaborn and have most of the items addressed. But I'm running into an issue with the first and last items in the plot. In the attached screenshot you can see that the first and last bar are at the edge of the figure when I want there to be space between the edge and bar.

bar graph

Here is the code that is creating the graph

fig, ax = plt.subplots(figsize=(17,10))



# variables for table
examiner_figure_title = (f'Examiner Production - {yesterday}')


# hide axes
fig.patch.set_visible(False)
fig.suptitle(examiner_figure_title, fontsize=24)

# variables for bar graph
x = yesterday_df['Production']
y = yesterday_df['Examiner']
    

ax = sns.barplot(x=x, y=y, hue=y, orient='h', ax=ax, palette=sns.color_palette())
ax.set(yticklabels=[])
ax.tick_params(left=False)
ax.bar_label
        
# change_width(ax, .75)
change_height(ax, 1)
ax.legend(bbox_to_anchor=(1, .5))
plt.show()

I've tried changing my figure size, thinking that might have been the cause. That did not impact the bar location.

I am using a custom height function to create bars rather than thin lines. If I don't apply the custom size of the bars the lines are not against the figure edge but you can't really see the lines, which is why I am using the custom setting. Perhaps I need to add something to the function? (attaching both the custom height and width for view)

def change_width(ax, new_value):
    for patch in ax.patches:
        current_width = patch.get_width()
        diff = current_width - new_value
        
        patch.set_width(new_value)
        
        patch.set_x(patch.get_x() + diff * .5)

def change_height(ax, new_value):
    for patch in ax.patches:
        current_height = patch.get_height()
        diff = current_height - new_value
        
        patch.set_height(new_value)
        
        patch.set_y(patch.get_y() + diff * .5)

Can anyone provide some insight on this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source