Creating bar charts with Matplotlib can be done using the bar()
function for vertical bars and barh()
for horizontal bars. Here are examples of both types:
Vertical Bar Chart
Horizontal Bar Chart
import matplotlib.pyplot as plt
# Data to plot
categories = ['A', 'B', 'C', 'D']
values = [3, 7, 5, 2]
# Create a horizontal bar chart
plt.barh(categories, values, color='green', edgecolor='black')
# Add titles and labels
plt.title('Horizontal Bar Chart')
plt.xlabel('Values')
plt.ylabel('Categories')
# Display the plot
plt.show()