Bar charts are used to plot and compare between different values of data. It can be plotted by using bar() function of the matplotlib module.

The syntax for plotting a bar graph in Python is:

matplotlib.pyplot.bar(xywidth=0.8bottom=None*align='center'data=None**kwargs)

A simple example of a bar chart in Python is given below.

import numpy as np
import matplotlib.pyplot as plt

languages = ('Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')
y_pos = np.arange(len(languages))
popularity = [10, 8, 6, 4, 2, 1]

# Plot the bar chart
plt.bar(y_pos, popularity, align='center')

# Setting the title and labels
plt.title('Programming language statistics')
plt.xlabel('Languages')
plt.ylabel('Popularity')
plt.xticks(y_pos, languages)

# Display the plot
plt.show()
Bar chart in Python

In Conclusion

Bar graphs are popularly used for data visualization in Python. You may like this tutorial on other kinds of plots in Python: Data Visualization in Python (With Tutorials).

LEAVE A REPLY

Please enter your comment!
Please enter your name here