Python Matplotlib क्या है? Line, Bar, Pie & Scatter Chart in Hindi | RBSE Class 12
Matplotlib क्या है?
Matplotlib Python की एक popular library है जिसका उपयोग data को graphs और charts के रूप में visualize करने के लिए किया जाता है।
Data को केवल numbers या tables के रूप में देखने की बजाय graph के रूप में दिखाने से trends और comparisons को समझना आसान हो सकता है।
Matplotlib का उपयोग क्यों किया जाता है?
- Data को graphically represent करने के लिए।
- Trends को समझने के लिए।
- Different values की comparison के लिए।
- Charts और graphs बनाने के लिए।
- Data analysis और visualization में।
Matplotlib Install कैसे करें?
pip install matplotlib
Matplotlib Import कैसे करें?
import matplotlib.pyplot as plt
यहाँ pyplot module को सामान्यतः plt alias के
साथ use किया जाता है।
पहला Line Chart
Line chart बनाने के लिए plt.plot() का उपयोग किया जा सकता है।
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 30, 25]
plt.plot(x, y)
plt.show()
Chart में Title लगाना
Chart का title बताने के लिए plt.title() का उपयोग किया जा
सकता है।
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 30, 25]
plt.plot(x, y)
plt.title("Student Performance")
plt.show()
X-axis और Y-axis Labels
X-axis और Y-axis को label देने के लिए xlabel() और
ylabel() methods का उपयोग किया जा सकता है।
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 30, 25]
plt.plot(x, y)
plt.title("Student Performance")
plt.xlabel("Test")
plt.ylabel("Marks")
plt.show()
Grid लगाना
Graph को पढ़ने में आसान बनाने के लिए grid दिखाई जा सकती है।
plt.plot(x, y)
plt.title("Student Performance")
plt.xlabel("Test")
plt.ylabel("Marks")
plt.grid()
plt.show()
Line Chart में Marker
Data points को highlight करने के लिए marker का उपयोग किया जा सकता है।
plt.plot(x, y, marker="o")
plt.show()
Bar Chart क्या है?
Bar Chart का उपयोग अलग-अलग categories की values की comparison करने के लिए किया जा सकता है।
Matplotlib में bar chart बनाने के लिए plt.bar() का उपयोग
किया जाता है।
import matplotlib.pyplot as plt
subjects = ["Hindi", "English", "Math", "Computer"]
marks = [75, 82, 90, 88]
plt.bar(subjects, marks)
plt.title("Subject Wise Marks")
plt.xlabel("Subjects")
plt.ylabel("Marks")
plt.show()
Horizontal Bar Chart
Horizontal bar chart बनाने के लिए plt.barh() का उपयोग
किया जा सकता है।
import matplotlib.pyplot as plt
subjects = ["Hindi", "English", "Math", "Computer"]
marks = [75, 82, 90, 88]
plt.barh(subjects, marks)
plt.title("Subject Wise Marks")
plt.show()
Pie Chart क्या है?
Pie Chart किसी total के अलग-अलग हिस्सों या proportions को दिखाने के लिए उपयोगी होता है।
Pie chart बनाने के लिए plt.pie() का उपयोग किया जा सकता है।
import matplotlib.pyplot as plt
subjects = ["Hindi", "English", "Math", "Computer"]
marks = [75, 82, 90, 88]
plt.pie(marks, labels=subjects)
plt.title("Marks Distribution")
plt.show()
Pie Chart में Percentage
Pie chart में percentage दिखाने के लिए autopct parameter
का उपयोग किया जा सकता है।
plt.pie(
marks,
labels=subjects,
autopct="%1.1f%%"
)
plt.title("Marks Distribution")
plt.show()
Scatter Plot क्या है?
Scatter Plot दो numerical variables के बीच relationship या distribution को देखने के लिए उपयोगी होता है।
Matplotlib में इसे बनाने के लिए plt.scatter() का उपयोग
किया जा सकता है।
import matplotlib.pyplot as plt
hours = [1, 2, 3, 4, 5, 6]
marks = [45, 50, 58, 65, 72, 80]
plt.scatter(hours, marks)
plt.title("Study Hours and Marks")
plt.xlabel("Study Hours")
plt.ylabel("Marks")
plt.show()
Multiple Lines एक Graph में
एक ही graph में एक से अधिक lines भी बनाई जा सकती हैं।
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
python_marks = [60, 70, 75, 85, 90]
math_marks = [55, 65, 72, 80, 88]
plt.plot(x, python_marks, label="Python")
plt.plot(x, math_marks, label="Math")
plt.title("Subject Performance")
plt.xlabel("Test")
plt.ylabel("Marks")
plt.legend()
plt.show()
Legend क्या है?
Legend graph में अलग-अलग lines या data series की पहचान करने में मदद करता है।
plt.legend()
Chart को Image के रूप में Save करना
Chart को file के रूप में save करने के लिए savefig() method
का उपयोग किया जा सकता है।
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 30, 25]
plt.plot(x, y)
plt.title("Sample Graph")
plt.savefig("graph.png")
plt.show()
Figure Size बदलना
Graph का size बदलने के लिए figsize parameter का उपयोग
किया जा सकता है।
import matplotlib.pyplot as plt
plt.figure(figsize=(8, 5))
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 30, 25]
plt.plot(x, y)
plt.show()
Line Style और Marker
Line chart में line style और marker को customize किया जा सकता है।
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 30, 25]
plt.plot(
x,
y,
linestyle="--",
marker="o"
)
plt.show()
Matplotlib के Important Functions
| Function | उपयोग |
|---|---|
| plt.plot() | Line chart बनाने के लिए |
| plt.bar() | Vertical bar chart |
| plt.barh() | Horizontal bar chart |
| plt.pie() | Pie chart |
| plt.scatter() | Scatter plot |
| plt.title() | Chart title |
| plt.xlabel() | X-axis label |
| plt.ylabel() | Y-axis label |
| plt.legend() | Legend दिखाने के लिए |
| plt.grid() | Grid दिखाने के लिए |
| plt.show() | Chart display करने के लिए |
| plt.savefig() | Chart save करने के लिए |
Line Chart और Bar Chart में अंतर
| Line Chart | Bar Chart |
|---|---|
| Trend दिखाने में उपयोगी | Categories की comparison में उपयोगी |
| plt.plot() का उपयोग | plt.bar() का उपयोग |
| Continuous या ordered data के लिए उपयोगी | Category-wise values के लिए उपयोगी |
Pie Chart और Scatter Plot
| Chart | मुख्य उपयोग |
|---|---|
| Pie Chart | Total में parts/proportions दिखाने के लिए |
| Scatter Plot | दो numerical variables के relationship/distribution को देखने के लिए |
Practical Example — Student Marks Visualization
import matplotlib.pyplot as plt
subjects = ["Hindi", "English", "Math", "Python"]
marks = [78, 82, 91, 88]
plt.bar(subjects, marks)
plt.title("Student Marks")
plt.xlabel("Subjects")
plt.ylabel("Marks")
plt.grid(axis="y")
plt.show()
RBSE Class 12 Important Questions
- Matplotlib क्या है?
- Matplotlib का उपयोग क्यों किया जाता है?
- Matplotlib को Python में कैसे import करते हैं?
- Line Chart क्या है?
- Bar Chart क्या है?
- Pie Chart क्या है?
- Scatter Plot क्या है?
- plt.plot() का उपयोग क्या है?
- plt.bar() का उपयोग क्या है?
- plt.pie() का उपयोग क्या है?
- plt.scatter() का उपयोग क्या है?
- plt.title() का उपयोग क्या है?
- xlabel() और ylabel() में क्या अंतर है?
- plt.legend() क्या करता है?
- plt.grid() का उपयोग क्यों किया जाता है?
- plt.show() का उपयोग क्या है?
- savefig() method क्या करता है?
- Line Chart और Bar Chart में अंतर लिखिए।
- Pie Chart का उपयोग कब किया जाता है?
- Scatter Plot का उपयोग क्यों किया जाता है?
Frequently Asked Questions (FAQs)
Matplotlib क्या है?
Matplotlib Python की एक plotting और visualization library है जिसका उपयोग विभिन्न प्रकार के charts और graphs बनाने के लिए किया जाता है।
Matplotlib को import कैसे करते हैं?
सामान्यतः import matplotlib.pyplot as plt का उपयोग किया
जाता है।
Line Chart बनाने के लिए कौन-सा function उपयोग होता है?
Line chart बनाने के लिए सामान्यतः plt.plot() का उपयोग
किया जाता है।
Bar Chart बनाने के लिए कौन-सा function उपयोग होता है?
Vertical bar chart के लिए plt.bar() और horizontal bar
chart के लिए plt.barh() का उपयोग किया जा सकता है।
Pie Chart बनाने के लिए कौन-सा function उपयोग होता है?
Pie chart बनाने के लिए plt.pie() का उपयोग किया जाता है।
Chart को image में कैसे save करते हैं?
Chart को image file में save करने के लिए plt.savefig()
का उपयोग किया जा सकता है।
अब अगला Topic पढ़ें
Matplotlib की विस्तृत जानकारी के लिए official documentation देखें।