Python Matplotlib ke Saath Data Visualization - Detailed Guide
text1. Matplotlib Kya Hai?
Matplotlib Python ki sabse popular library hai data visualization ke liye. Yeh flexible aur powerful hai jiske zariye aap different tarah ke graphs, plots aur charts create kar sakte hain jaise line plots, bar charts, scatter plots, histograms, aur pie charts.
Iska "pyplot" module MATLAB jaise syntax deta hai jo beginners ke liye seekhna aasan banata hai.
2. Installation Aur Import
Pehle Matplotlib install karo apne environment me:
pip install matplotlib
Phir Python me import karo:
import matplotlib.pyplot as plt
3. Basic Line Plot Banana
Aayiye ek simple line plot banate hain:
x = y = plt.plot(x, y) plt.title("Simple Line Plot") plt.xlabel("X Axis") plt.ylabel("Y Axis") plt.show()
Yeh code x aur y ke data points ko line se jod kar plot karta hai. Titles aur axis labels se visualization ko samajhna aasan hota hai.
text4. Bar Chart Banana
Bar chart categorical data dikhane ke liye best hota hai:
categories = ['Apple', 'Banana', 'Cherry', 'Date'] values = plt.bar(categories, values, color='skyblue') plt.title("Fruit Count Bar Chart") plt.show()text
5. Histogram Plot Karna
Histogram data distribution dikhata hai, matlab kis range me kitni values hain:
data = plt.hist(data, bins=5, color='green', edgecolor='black') plt.title("Histogram") plt.show()text
6. Scatter Plot Banana
Scatter plot 2 variables ke beech relationship dikhata hai, jaise points ke form me:
x = y = plt.scatter(x, y, color='red') plt.title("Scatter Plot") plt.show()text
7. Pie Chart
Pie chart se apko pata chalta hai proportions (percentage) of categories:
labels = ['Python', 'Java', 'C++', 'JavaScript'] sizes = plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140) plt.title("Programming Languages Popularity") plt.show()text
8. Multiple Graphs Ek Sath Plot Karna
Agar aapko plot me ek se zyada lines dikhani hai to:
x = plt.plot(x, , label='Squared') plt.plot(x, , label='Cubed') plt.legend() plt.title("Multiple Lines Plot") plt.show()text
9. Plot Customization
Matplotlib me aap color, line style, markers set kar sakte hain:
plt.plot(x, , color='purple', linestyle='--', marker='o') plt.title("Customized Line Plot") plt.xlabel("X") plt.ylabel("Y") plt.grid(True) plt.show()text
10. Summary
Matplotlib Python programming ke liye ek fundamental visualization library hai. Iske functions aur methods se aap apne data ko visually samajh sakte hain aur communicate kar sakte hain. Line plots, bar charts, scatter plots, histograms, aur pie charts jaisi common visualizations ko itni flexibility ke saath banana iska strength hai. Beginners ke liye ise seekhna zaruri hai kyunki data science aur machine learning me visualization ek important skill hai.
Practice karte rahein aur alag alag plots bana kar apni skill ko improve karein!