Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22875

IslandT: Matplotlib Tutorial — Create a bar chart

$
0
0

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:-


Viewing all articles
Browse latest Browse all 22875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>