Matplotlib Bars 📊
Bar Graphs
Use bar() for vertical bars and barh() for horizontal bars.
✨ Vertical Bars
python
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])
plt.bar(x,y)
plt.show()↔️ Horizontal Bars
python
plt.barh(x, y)🎨 Customization
You can change color and width/height.
python
# Vertical: width
plt.bar(x, y, color = "red", width = 0.1)
# Horizontal: height
plt.barh(x, y, color = "hotpink", height = 0.1)