-1
import numpy as np
import matplotlib.pyplot as plt

product_category = np.array(['Furniture', 'Technology', 'Office Supplies'])
sales = np.array ([4110451.90, 4744557.50, 3787492.52] )
plt.bar(product_category, sales, width= 0.5, align='center', edgecolor='Orange',color='cyan')
plt.title("Sales Across Product Categories\n", fontdict={'fontsize': 20, 'fontweight' : 5, 'color' :'Green'})
plt.xlabel("Product Category", fontdict={'fontsize': 12, 'fontweight' : 5, 'color' : 'Brown'})
plt.ylabel("Sales", fontdict={'fontsize': 12, 'fontweight' : 5, 'color' : 'Brown'})
ticks = np.arange(0, 6000000, 1000000)
labels = ["{}M".format(i//1000000) for i in ticks] 
plt.yticks(ticks, labels)
plt.show() 

labels = ["{}M".format(i//1000000) for i in ticks] :: explanation for this

Mike Scotty
  • 8,981
  • 5
  • 28
  • 42

1 Answers1

1
labels = ["{}M".format(i//1000000) for i in ticks] 

This expression is a "list comprehension", which means, labels is a list with a formated string for each item in ticks.

"{}M".format(i//1000000)

This is string formating, the {} with be replaced by the results of i//1000000.