Data Visualization ππ¨πΊοΈ
See the pattern. Tell the story. Change the decision. Charts make the invisible impossible to ignore!
Day 57: Data Visualization β Make Patterns Impossible to Miss!
Why Should I Care?
Look at a table of city temperatures β Mumbai 38, Delhi 42, Chennai 36, Hyderabad 40, Kolkata 35. Can you immediately spot the heat wave? Probably not. Now show that same data as a coloured bar chart and Delhi's 42 degree bar jumps out instantly. The data did not change. The picture did. That is what visualization does β it makes truth impossible to miss!
Your First Chart
import matplotlib.pyplot as plt
names = ["Rohith", "Sneha", "Arjun", "Priya", "Kiran"]
scores = [87, 92, 45, 76, 63]
plt.bar(names, scores)
plt.show()
plt.bar() creates the chart. plt.show() renders it on screen. Without show() the chart is created in memory but never displayed β it simply disappears. Two lines turned a list of numbers into a visual story!
A Professional Chart
import matplotlib.pyplot as plt
names = ["Rohith", "Sneha", "Arjun", "Priya", "Kiran"]
scores = [87, 92, 45, 76, 63]
plt.figure(figsize=(8, 4))
plt.bar(names, scores, color="steelblue")
plt.title("Student Scores β RohithBuilds Batch")
plt.xlabel("Student")
plt.ylabel("Score")
plt.tight_layout()
plt.show()
figsize sets the canvas size. color makes bars steelblue. title names the chart. xlabel and ylabel label the axes β unlabelled charts are unreadable. tight_layout stops labels from being cut off at edges. This is how every professional chart is built!
Pick the Right Chart for Your Story
Bar chart β comparing categories. Who scored highest? Which city is hottest? Use when X is categories and Y is values. Line chart β showing trends over time. How did sales grow month by month? Use when data has a sequence. Pie chart β showing proportions. What percentage of users are premium? Use for parts of a whole. Scatter plot β showing relationships. Does studying more lead to higher scores? Use to find correlations. Right chart equals right story!
Real World Connection
When IPL shows win percentage by team β bar chart. When Zomato shows order volume growing month by month β line chart. When a news channel shows election vote share β pie chart. When a scientist checks if temperature affects cricket scores β scatter plot. Every dashboard you have ever seen on any news channel, sports app or business report is just matplotlib charts built by code exactly like this!
Common Mistakes
Mistake 1 β Forgetting plt.show().
plt.bar(names, scores)
# WRONG β chart created but nothing appears!
plt.bar(names, scores)
plt.show()
# CORRECT β chart renders on screen!
Mistake 2 β Swapping X and Y arguments.
plt.bar(scores, names) # WRONG β broken unreadable chart!
plt.bar(names, scores) # CORRECT β X is categories, Y is values. Always!
Mini Challenge
Mini Challenge
Create a bar chart of the top 5 IPL teams and their wins this season. Add a title, xlabel and ylabel. Use a colour other than steelblue. Then create a second chart β a line chart of your own monthly screen time over 6 months using plt.plot() instead of plt.bar(). You just built the same charts that every sports analytics dashboard and personal health app shows its users!
Quick Quiz
Q: What does plt.show() do and why can you never skip it? A: It renders the chart on screen. Without it the chart is created in memory but never displayed!
Q: Which argument comes first in plt.bar() β categories or values? A: Categories always first, values second β plt.bar(names, scores)!
Q: Which chart type would you use to show how app downloads grew month by month? A: Line chart β it shows trends and changes over time!
Key Takeaways
Key Takeaways
- Visualization turns numbers into patterns that are impossible to miss.
- plt.bar(X, Y) creates a bar chart. plt.show() renders it β never skip show()!
- Always add title, xlabel and ylabel β unlabelled charts are unreadable.
- X is always categories, Y is always values β swapping them breaks the chart.
- Numbers tell the truth. Charts make people believe it!
Continue Learning with Rohi
You've used your 3 free Rohi questions. Create a free account to continue learning.