To create a histogram where the value rounded to 2 decimals defines the bin, you can create bin edges halfway between these values. E.g. bin edges at 0.195
and 0.205
would define the bin around 0.20
. You can use `np.arange(-0.005, 1.01, 0.01)' to create an array with these bin edges.
In order to only set tick labels at the used positions, you can use ax.set_yticks()
. You can round all the y-values and use the unique values for the y ticks.
If you don't want rounding, but truncation, you could use bins=np.arange(0, 1.01, 0.01)
and ax.set_yticks(np.unique(np.round(y-0.005, 2)))
.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
import seaborn as sns
y = np.array([0.96270, 0.93870, 0.93610, 0.69610, 0.61250, 0.61280, 0.52965, 0.50520])
ax = sns.histplot(y=y, bins=np.arange(-0.005, 1.01, 0.01), color='crimson')
ax.set_yticks(np.unique(np.round(y, 2)))
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
ax.tick_params(axis='y', labelsize=6)
ax.set_xlabel("frequency", fontsize=15)
ax.set_ylabel("results", fontsize=15)
plt.show()
Note that even with a small fontsize the tick labels can overlap.

Another approach, is to use a countplot
on the rounded (or truncated) values. Then the bars get evenly spaced, without taking empty spots into account:
y = np.array([0.96270, 0.93870, 0.93610, 0.69610, 0.61250, 0.61280, 0.52965, 0.50520])
y_rounded = [f'{yi:.2f}' for yi in sorted(y)]
# y_truncated = [f'{yi - .005:.2f}' for yi in sorted(y)]
ax = sns.countplot(y=y_rounded, color='dodgerblue')
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
