0

I have created a histogram and everything is working, the only thing that is missing is a thousands separator for the y-axis. How can I fit one in conveniently? None of the other documented answers worked, unfortunately.

# Creating a histogram for order_hour_of_day with titles, labels for the axes and 
#thousands separator (last is still missing)
hist2 = df_final['order_hour_of_day'].plot.hist(bins = 24)
plt.title('Orders per Hour of Day')
plt.xlabel('Hour of Day')
plt.ylabel('Orders')
plt.ticklabel_format(style='plain', axis='y')

Thank you!

DataVE
  • 59
  • 8
  • No, actually it just confuses me a lot because of my skill level, sorry – DataVE Jan 18 '22 at 15:43
  • `hist2.yaxis.set_major_formatter(matplotlib.ticker.StrMethodFormatter('{x:,.0f}'))` or any other method listed in the duplicate link but remove the line `plt.ticklabel_format(style='plain', axis='y')`. – Mr. T Jan 18 '22 at 17:03

1 Answers1

0

hope this helps. It implements one of the answers from @Mr.T 's comment. I used the default dataset 'mpg' from seaborn.

import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter, StrMethodFormatter
import seaborn as sns

sns.get_dataset_names() #these are the available example datasets from seaborn
mpg = sns.load_dataset('mpg') 
display(mpg) #shows the dataframe

fig, ax = plt.subplots()
ax.hist = mpg['weight'].plot.hist(bins = 24)
ax.xaxis.set_major_formatter(StrMethodFormatter('{x:,}'))

Output looks like this:

enter image description here

LynneKLR
  • 90
  • 1
  • 8