In this post i'm not talking about how bins are calculated.
I want that the first bin gets located at the beginning of the X-axis.
In other words :
I want that the first bin gets located where is the Y-axis
Here is my source code :
import random
import pandas as pd
from matplotlib import pyplot as plt
# Preparing the variable
data = {}
data["values"] = [random.randint(0,50) for x in range(200)]
df = pd.DataFrame(data)
# Creation of the figure
plt.figure(figsize = (10, 10))
plt.subplot(1, 1, 1)
# Creation of my bins
mybins = [-0.5+x for x in range(0,52)]
# Creation of the chart
plt.hist(df["values"], bins=mybins,
rwidth=0.7, align="mid")
plt.xticks(list(range(0, 51, 5)))
plt.show()
As an output i get this histogram :
As you can see, there is blank space between the Y-axis and the first bin.