January 2019
Beginner
318 pages
8h 23m
English
A bar chart is a chart that represents your data in rectangular bars. You can plot them vertically or horizontally. Create a script called bar_chart.py and write the following content in it:
import matplotlib.pyplot as pltfrom matplotlib import stylestyle.use('ggplot')x1 = [4,8,12]y1 = [12,16,6]x2 = [5,9,11]y2 = [6,16,8]plt.bar(x1,y1,color = 'g',linewidth=3)plt.bar(x2,y2,color = 'r',linewidth=3)plt.title("Bar plot")plt.xlabel("x axis")plt.ylabel("y axis")plt.show()
Run the script and you will get the following output:
student@ubuntu:~/work$ python3 bar_chart.py
The output is as follows:

In the preceding example, we have two sets ...
Read now
Unlock full access