In this Matplotlib example, I am going to create a bar chart to represent the quantity of the wear I have sold recently.
import matplotlib.pyplot as plt fig, ax = plt.subplots() wear = ['Slipper', 'Sport Shoe', 'Snicker', 'High Heel'] counts = [100, 150, 35, 16] bar_labels = ['Slipper', 'Sport Shoe', 'Snicker', 'High Heel'] bar_colors = ['tab:green', 'tab:brown', 'tab:blue', 'tab:red'] ax.bar(wear, counts, label=bar_labels, color=bar_colors) ax.set_ylabel('Wear Sale Quantity') ax.set_title('Wear Sales') ax.legend(title='Wear Sale') plt.show()
Just like before, I am using the matplotlib.pyplot module to help me to plot the below chart. After calling the subplots method two objects have been returned and I am going to use the second object to set up all the elements within the bar chart which is displayed as follows:-