Data Visualization ek process hai jisme raw data ko charts, graphs, plots aur dashboards ke through visual form me present kiya jata hai. Isse complex data ko samajhna kaafi easy ho jata hai aur hum quickly trends, patterns, relationships aur outliers identify kar sakte hain.
Exploratory vs Explanatory Visualizations
Har visualization ka purpose same nahi hota. Data Science aur Analytics me generally visualizations do categories me divide kiye jate hain:
Exploratory Visualizations
Explanatory Visualizations
1. Exploratory Visualizations
Exploratory Visualizations data analysis ke starting phase me banaye jate hain. Inka purpose data ko explore karna aur usme hidden patterns ya problems ko identify karna hota hai.
Ye visualizations mostly analyst ya data scientist khud ke liye banata hai.
2. Explanatory Visualizations
Explanatory Visualizations ka purpose kisi specific insight ko clearly communicate karna hota hai. Ye charts presentation, reports aur dashboards me use kiye jate hain.
Ye visualizations clean, attractive aur audience-friendly hote hain.
Exploratory vs Explanatory Visualization
Aspect | Exploratory Visualization | Explanatory Visualization |
|---|---|---|
Goal | Data me hidden insights find karna | Insights ko clearly explain karna |
Audience | Data Analyst / Data Scientist | Stakeholders / Clients / Management |
Style | Flexible, raw aur detailed | Clean, polished aur presentation-ready |
Focus | Multiple patterns explore karna | Ek specific insight highlight karna |
Use Case | Data Analysis | Reports aur Presentations |
Plotting Charts using Matplotlib
Python me visualization ke liye sabse popular aur widely used library Matplotlib hai. Ye Data Science, Machine Learning, Business Analytics aur Scientific Research me standard library mani jati hai.
Matplotlib ki help se aap simple line chart se lekar highly customized professional visualizations tak sab kuch create kar sakte hain.
Is chapter me aap seekhenge:
Matplotlib kya hai
matplotlib.pyplotkya hota haiPlot create kaise karte hain
Labels aur Titles add karna
Multiple Lines plot karna
Legends ka proper use
Colors aur Line Styles
Built-in Styles
Professional looking charts banana
Common mistakes aur Best Practices
What is Matplotlib?
Matplotlib Python ki sabse popular visualization library hai jo charts aur graphs create karne ke liye use hoti hai.
Ye almost har tarah ke visualization ko support karti hai, jaise:
Line Plot
Bar Chart
Histogram
Scatter Plot
Pie Chart
Box Plot
Area Plot
Heatmap (Seaborn ke saath)
Subplots
Statistical Charts
Matplotlib itni flexible hai ki aap graph ka almost har element customize kar sakte hain.
Why Use Matplotlib?
Agar aap Data Science ya Data Analysis me career banana chahte hain, to Matplotlib seekhna bahut important hai.
Matplotlib ke Advantages
Python ki most widely used visualization library
Complete customization support
Publication-quality graphs
Pandas aur NumPy ke saath excellent integration
Seaborn bhi internally Matplotlib ka hi use karta hai
Industry me sabse zyada use hone wali plotting library
What is matplotlib.pyplot?
Matplotlib ke andar pyplot naam ka ek module hota hai jo graphs create karne ke liye use hota hai.
Agar Matplotlib ko ek drawing application maan lein, to pyplot uska drawing tool ya paintbrush hai.
Is module ko hum generally short alias plt ke naam se import karte hain.
import matplotlib.pyplot as plt
Yahan plt sirf ek shortcut naam hai jo code ko chhota aur readable banata hai.
Understanding the Basic Plotting Workflow
Matplotlib me almost har graph banane ka process same hota hai.
Import Library
↓
Prepare Data
↓
Create Plot
↓
Customize Plot
↓
Display Plot
Ye workflow aapko almost har visualization me use karna hoga.
Your First Plot
Ab apna pehla graph banate hain.
import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,5,6])
plt.show()
Output me ek simple line chart display hoga.
What is plt.show()?
plt.show() graph ko screen par display karta hai.
Agar aap Python script run kar rahe hain aur plt.show() call nahi karte, to kai environments me graph display hi nahi hoga.
Notebook environments (Jupyter, Google Colab) me kai baar graph automatically display ho jata hai, lekin normal Python scripts me plt.show() likhna best practice hai.
Example
Main Virat Kohli ODI Runs (Hypothetical Data) ka example use karunga, kyunki cricket data relatable hai aur line chart ke liye perfect bhi.
Dataset
import matplotlib.pyplot as plt
years = [2015,2016,2017,2018,2019,2020,2021,2022,2023,2024]
runs = [640,739,1460,1202,1377,842,964,765,1377,903]
Ye data different years me Virat Kohli ke hypothetical ODI runs ko represent karta hai.
Step 1 – Basic Plot
plt.plot(years, runs)
plt.show()
Output:
Simple line chart.
Problem:
Title nahi hai
Labels nahi hain
Viewer ko samajh nahi aa raha graph kya represent karta hai.
Step 2 – Add Title and Axis Labels
plt.plot(years, runs)
plt.title("Virat Kohli ODI Runs")
plt.xlabel("Year")
plt.ylabel("Runs")
plt.show()
Ab graph dekhte hi user ko samajh aa jata hai:
X-axis → Year
Y-axis → Runs
Graph kis player ka hai
Step 3 – Add Marker
plt.plot(
years,
runs,
marker="o"
)
plt.title("Virat Kohli ODI Runs")
plt.xlabel("Year")
plt.ylabel("Runs")
plt.show()
Why Use Markers?
Marker har data point ko clearly highlight karta hai.
Ye especially useful hota hai jab observations kam hon.
Common Markers
Marker | Description |
|---|---|
o | Circle |
s | Square |
^ | Triangle |
* | Star |
x | Cross |
Step 4 – Change Line Color
plt.plot(
years,
runs,
color="blue",
marker="o"
)
Color visualization ko attractive banata hai.
Common Colors
blue
red
green
orange
purple
black
Step 5 – Change Line Style
plt.plot(
years,
runs,
color="blue",
linestyle="--",
marker="o"
)
Common Line Styles
Style | Meaning |
|---|---|
- | Solid |
-- | Dashed |
-. | Dash Dot |
: | Dotted |
Step 6 – Increase Line Width
plt.plot(
years,
runs,
color="blue",
marker="o",
linewidth=3
)
Thicker lines presentation aur reports me zyada readable lagti hain.
Step 7 – Add Grid
plt.plot(
years,
runs,
color="blue",
marker="o",
linewidth=3
)
plt.grid(True)
Grid values compare karna easy bana deta hai.
Step 8 – Add Figure Size
plt.figure(figsize=(10,5))
plt.plot(
years,
runs,
color="blue",
marker="o",
linewidth=3
)
plt.grid(True)
figsize graph ki width aur height control karta hai.
Example
figsize=(8,4)
figsize=(10,5)
figsize=(12,6)
Step 9 – Add Legend
plt.plot(
years,
runs,
color="blue",
marker="o",
linewidth=3,
label="Virat Kohli"
)
plt.legend()
Agar future me multiple players add karne hon to legend automatically identify kar dega.
Step 10 – Apply a Style
plt.style.use("ggplot")
Ya
plt.style.use("fivethirtyeight")
Built-in styles graph ko instantly professional look dete hain.
Final Professional Chart
import matplotlib.pyplot as plt
years = [2015,2016,2017,2018,2019,2020,2021,2022,2023,2024]
runs = [640,739,1460,1202,1377,842,964,765,1377,903]
plt.style.use("ggplot")
plt.figure(figsize=(10,5))
plt.plot(
years,
runs,
color="blue",
marker="o",
linewidth=3,
linestyle="-",
markersize=8,
label="Virat Kohli"
)
plt.title("Virat Kohli ODI Runs (2015–2024)", fontsize=16)
plt.xlabel("Year", fontsize=12)
plt.ylabel("Runs", fontsize=12)
plt.xticks(years)
plt.grid(True, alpha=0.3)
plt.legend()
plt.tight_layout()
plt.show()
Output Preview
Customizations We Applied
Customization | Purpose |
|---|---|
| Apply a professional theme |
| Control chart size |
| Change line color |
| Highlight each data point |
| Increase marker visibility |
| Make the line thicker |
| Change line appearance |
| Describe the chart |
| Label the X-axis |
| Label the Y-axis |
| Show all year values clearly |
| Identify the plotted series |
| Improve readability |
| Prevent labels from overlapping |
Ye section blog me bahut strong lagega, kyunki reader ko ek hi real example ke through lagbhag saari important Matplotlib customizations practical tareeke se samajh aa jayengi.
Virat Kohli ODI Runs (2015–2024)
Hypothetical yearly ODI runs used to demonstrate Matplotlib chart customization.
year | runs |
|---|---|
2015 | 640 |
2016 | 739 |
2017 | 1,460 |
2018 | 1,202 |
2019 | 1,377 |
2020 | 842 |
2021 | 964 |
2022 | 765 |
2023 | 1,377 |
2024 | 903 |