Thursday, November 13, 2025

All Types of Matplotlib Charts Explained with Python Lists

 

🎨 1. Line Chart

import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [10, 20, 15, 25, 30] plt.plot(x, y) plt.title("Line Chart Example") plt.xlabel("X Values") plt.ylabel("Y Values") plt.show()

πŸ“¦ 2. Bar Chart (Vertical)

import matplotlib.pyplot as plt names = ["A", "B", "C", "D"] marks = [80, 60, 90, 75] plt.bar(names, marks) plt.title("Bar Chart Example") plt.xlabel("Students") plt.ylabel("Marks") plt.show()

πŸ“ 3. Bar Chart (Horizontal)

import matplotlib.pyplot as plt cities = ["Delhi", "Mumbai", "Chennai", "Kolkata"] population = [30, 20, 15, 10] plt.barh(cities, population) plt.title("Horizontal Bar Chart") plt.xlabel("Population (in millions)") plt.show()

🍩 4. Pie Chart

import matplotlib.pyplot as plt labels = ["Python", "Java", "C++", "JS"] sizes = [40, 25, 20, 15] plt.pie(sizes, labels=labels, autopct="%1.1f%%", startangle=90) plt.title("Pie Chart Example") plt.show()

πŸͺœ 5. Scatter Plot

import matplotlib.pyplot as plt x = [10, 20, 30, 40, 50] y = [15, 25, 20, 30, 35] plt.scatter(x, y) plt.title("Scatter Plot Example") plt.xlabel("X Axis") plt.ylabel("Y Axis") plt.show()

🎚 6. Histogram

import matplotlib.pyplot as plt ages = [12, 23, 25, 30, 45, 50, 15, 20, 18, 25, 34, 55] plt.hist(ages, bins=5) plt.title("Histogram Example") plt.xlabel("Age Groups") plt.ylabel("Frequency") plt.show()

πŸŽ› 7. Box Plot

import matplotlib.pyplot as plt data = [20, 22, 23, 25, 30, 35, 40, 45, 50] plt.boxplot(data) plt.title("Box Plot Example") plt.ylabel("Values") plt.show()

πŸŽ— 8. Area Chart

import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [2, 4, 1, 5, 7] plt.fill_between(x, y, color="skyblue", alpha=0.5) plt.plot(x, y) plt.title("Area Chart Example") plt.show()

πŸ”— 9. Multiple Line Chart

import matplotlib.pyplot as plt x = [1, 2, 3, 4] y1 = [10, 20, 15, 30] y2 = [5, 25, 20, 35] plt.plot(x, y1, label="Sales 2023") plt.plot(x, y2, label="Sales 2024") plt.title("Multiple Line Chart") plt.xlabel("Quarters") plt.ylabel("Values") plt.legend() plt.show()

πŸ”„ 10. Stacked Bar Chart

import matplotlib.pyplot as plt months = ["Jan", "Feb", "Mar", "Apr"] product_A = [20, 35, 30, 35] product_B = [25, 32, 34, 20] plt.bar(months, product_A, label="Product A") plt.bar(months, product_B, bottom=product_A, label="Product B") plt.title("Stacked Bar Chart") plt.legend() plt.show()

πŸ“Š 11. Donut Chart (Pie With Center Hole)

import matplotlib.pyplot as plt sizes = [50, 25, 15, 10] labels = ["A", "B", "C", "D"] plt.pie(sizes, labels=labels, autopct="%1.1f%%") circle = plt.Circle((0,0), 0.7, color="white") plt.gca().add_artist(circle) plt.title("Donut Chart Example") plt.show()

πŸ•Έ 12. Radar Chart

import matplotlib.pyplot as plt import numpy as np labels = ["Speed", "Accuracy", "Skill", "Power", "Stamina"] values = [80, 70, 65, 90, 75] angles = np.linspace(0, 2*np.pi, len(labels), endpoint=False) values = np.concatenate((values, [values[0]])) angles = np.concatenate((angles, [angles[0]])) plt.polar(angles, values) plt.fill(angles, values, alpha=0.3) plt.title("Radar Chart Example") plt.show()

No comments:

Post a Comment

Machine Learning with Python : Scratch to Advanced

https://claude.ai/public/artifacts/d515bb8c-40dd-4d9a-9010-beb96f6aa4e5