Python डेटा विज़ुअलाइज़ेशन
import matplotlib.pyplot as plt
plt.bar(categories, values)
plt.xlabel("label")
plt.ylabel("label")
plt.show()
Bar Charts बनाना
plt.bar() vertical bars खींचता है (या horizontal के लिए plt.barh()) जिनकी height हर category की value के अनुपात में होती है, जिससे मुट्ठी भर discrete categories की तुलना करते समय bar charts स्वाभाविक पसंद बन जाते हैं।
उदाहरण: Drawing Bar Charts
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
plt.bar(["A", "B", "C"], [10, 20, 15]) # bar height proportional to each value
plt.savefig("bar.png")
Scatter Plots बनाना
plt.scatter() हर data point को उसकी x और y values के हिसाब से एक dot के रूप में अलग-अलग plot करता है, बिना उन्हें किसी line से जोड़े। इससे scatter plots दो numeric variables के आपस में correlated दिखने या न दिखने की visually जाँच करने का standard तरीका बन जाते हैं।
उदाहरण: Drawing Scatter Plots
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
plt.scatter([1, 2, 3], [4, 1, 5]) # each point plotted individually, no connecting line
plt.savefig("scatter.png")
Histograms बनाना
plt.hist() continuous numeric data को bins कहे जाने वाले ranges के एक set में बाँटता है और हर bin की count के लिए एक bar खींचता है, जिससे distribution का overall आकार -- चाहे वो लगभग symmetric हो, skewed हो, या कई peaks वाला हो -- ऐसे तरीके से सामने आता है जो numbers की raw list कभी नहीं दिखा सकती।
उदाहरण: Drawing Histograms
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
plt.hist([1, 2, 2, 3, 3, 3, 4]) # sorts values into bins and draws a bar per bin
plt.savefig("hist.png")
Pie Charts बनाना
plt.pie() हर category को total में उसके हिस्से के अनुसार आकार वाले circle के एक proportional wedge के रूप में खींचता है।
Pie charts तब सबसे अच्छे काम करते हैं जब categories कम हों और साफ़ तौर पर किसी meaningful whole में जुड़ती हों; ज़्यादा slices chart को गड्डमड्ड और सटीक तुलना करने में मुश्किल बना देते हैं।
उदाहरण: Drawing Pie Charts
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
plt.pie([30, 20, 50], labels=["A", "B", "C"]) # each wedge sized by its share of the total
plt.savefig("pie.png")
Subplots बनाना
plt.subplots(rows, cols) एक ही figure के भीतर independent axes की एक grid बनाता है, जिससे आप कई related charts को सीधी तुलना के लिए साथ-साथ दिखा सकते हैं, अलग-अलग images बनाने की बजाय जिन्हें viewer को मानसिक रूप से एक-सीध में लाना पड़ता।
उदाहरण: Creating Subplots
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, 2) # 1 row, 2 columns of independent charts
axes[0].plot([1, 2, 3])
axes[1].bar(["A", "B"], [5, 10])
plt.savefig("subplots.png")
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first:
- Python NumPy Introduction
- Python NumPy Arrays
- Python Pandas Introduction
- Python Pandas DataFrame
- Python Matplotlib Basics
- Python Data Visualization
- Python Statistics Module
- Python CSV & Data Analysis
- Python requests Module
- Python JSON & APIs
- Python Web Scraping Basics
- Python Flask Introduction
- Python Django Introduction
- Python MongoDB