A bar plot is a type of statistical chart used to represent data through direct bar plots and horizontal bar plots.
Each column typically represents a value (or a group of values), and the height (or length) of the column indicates the magnitude of that value.
You can draw bar plots using the Matplotlib library:
import matplotlib.pyplot as plt
Draw a direct bar plot with Python using matplotlib.pyplot.bar()
import matplotlib.pyplot as plt
# Data for the bar plot
categories = ['A', 'B', 'C', 'D', 'E', 'F']
values = [10, 25, 15, 33, 30, 45]
# Create the bar plot
plt.bar(categories, values)
# Add labels and title
plt.xlabel('Category')
plt.ylabel('Value')
plt.title('Direct Bar Plot')
plt.show()
Output:
Draw a horizontal bar plot with Python using matplotlib.pyplot.barh()
# Data for the bar plot
categories = ['A', 'B', 'C', 'D', 'E', 'F']
values = [10, 25, 15, 33, 30, 45]
# Create the bar plot
plt.barh(categories, values)
# Add labels and title
plt.xlabel('Value')
plt.ylabel('Category')
plt.title('Horizontal Bar Plot')
plt.show()
Output: