I am trying to draw a countplot for movie ratings data overlayed with a vertical line that represents the median. I am having success by plotting the countplot:
But when I try to draw a vertical line using the column's median, but it's drawn on the wrong place:
That happens because the columns median is 4, so pyplot tries do draw the line on the 4th tick (starting at 0). I could manually convert the scale but i want to know if there is a more ortodox way of sharing the same scale with both figures. I have tried using plt.xticks(np.arange(0, 5, step=0.5) but it didn't work. Here
fig, ax = plt.subplots(figsize=(9,6))
plt.xticks(np.arange(0, 5, step=0.5))
sns.countplot(x=df['Latest Rating'], ax=ax).set(title="Latest Rating distribution")
plt.axvline(x=df['Latest Rating'].median(),
color='blue',
ls='--',
lw=2.5)
I have tried setting the xticks manually and tried using a separated axis. Both times the result was the same as the print annexed in the question, the second plot still used the wrong scale