I'm trying to create a simple histogram with the x-axis as years and the y-axis as the count of each year. Using pandas, I created a data frame, called df1, from a CSV seen below, where it's just a single column of years. dataframe created from CSV of years
Next, I have
figure(figsize=(8, 8), dpi=80)
plt.hist(df1,bins=19)
Which outputs a histogram with undesirable x-ticks. I can see that both arrays make sense, but the x-ticks themselves don't really make sense. I'd rather each bar have its own year as its x-tick label.
Now, I tried to set the number of bins to 19 because the first year starts in 2003 and ends in 2022, but did not seem to solve the issue. Any suggestions or help would be greatly appreciated.
You don't need a histogram. If you have discrete values and want one value per bin, you can simply count
the values per year and plot the counts as a bar plot:
df.groupby('Date Published')['Date Published'].count().plot.bar()
sns.histplot(df, discrete=True)