There is a big space between the border/x-axe of the graph and the first and last bar in a bar plot in pyplot (red arrows in the first picture). In the image below, it looks fine in the graph on the left, but it's wasting a lot of space in the graph on the right. The larger the graph, the larger the space.
See how much space is wasted in the second picture:
Any idea how to fix that?
The code:
plt.figure(figsize=figsize)
grid = plt.GridSpec(figsize[1], figsize[0], wspace=120/figsize[0])
plt.suptitle(feature.upper())
# NaN plot
plt.subplot(grid[:, :2])
plt.title('Présence')
plt.ylabel('occurences')
plt.bar([0, 1], [df.shape[0] - nan, nan], color=['#4caf50', '#f44336'])
plt.xticks([0, 1], ['Renseigné', 'Absent'], rotation='vertical')
# Distrib plot
plt.subplot(grid[:, 2:])
plt.title('Distribution')
x_pos = [i for i, _ in enumerate(sizes)]
plt.bar(x_pos, sizes)
plt.xticks(x_pos, labels, rotation='vertical')
plt.show()
df is my pandas DataFrame, nan the amount of null value for the feature I'm plotting, sizes is the number of occurrences for each value, and labels are the corresponding label's value.
