If we plot very simple histogram:
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
Z = np.array([1, 2, 2, 2, 2, 2, 2, 3, 4, 5])
sns.histplot(Z, bins = 5)
plt.xticks([1, 2, 3, 4, 5])
plt.show()
we obtain:
my question is - is there any possibility to have those ticks centered with respect to bin? i.e. I want to have tick 1
in the middle of the first bin, tick 2
in the middle of second bin i.e.
Do you know if it is possible?
As suggested in a comments, I used discrete = True
and it worked. However, I don't understand why it brakes when it comes to creating subplots:
sns.set(rc={'figure.figsize':(10,15)})
X = np.array([1, 1, 1, 1, 1, 1, 2, 3, 4, 5])
Y = np.array([1, 2, 3, 4, 5, 5, 5, 5, 5, 5])
Z = np.array([1, 2, 2, 2, 2, 2, 2, 3, 4, 5])
f, axes = plt.subplots(1, 3)
sns.histplot(X, color = "b", ax = axes[0], discrete = True)
plt.xticks(np.arange(1, 6))
sns.histplot(Y, color = "r", ax = axes[1])
plt.xticks([1, 2, 3, 4, 5])
sns.histplot(Z, bins = 5, color = "g", ax = axes[2])
plt.xticks([1, 2, 3, 4, 5])
plt.show()
Do you know why it happens?