Matplotlib என்பது Python-ல் graphs, charts, plots, and data visualizations உருவாக்க பயன்படும் major visualiza……
Matplotlib
Matplotlib என்பது Python-ல் graphs, charts, plots, and data visualizations உருவாக்க பயன்படும் major visualization library. Official Matplotlib documentation இதை static, animated, interactive visualizations உருவாக்கும் comprehensive Python …
x = [1, 2, 3] y = [10, 20, 30] plt.plot……
Suppose student marks: Arun = 80 Bala = 90 Kumar = 70 Numbers மட்டும் பார்த்தால்: 80 90 70 difference உடனடியா……
↓ Pattern / Trend கண்டுபிடித்த……
Raw Data ↓ Python List / NumPy Array / Pandas Data ↓ Import Matplotlib ↓ Choose Plot Type ↓ Create Plot ↓ ……
Here: matplotlib → Library pyplot → Plotting interface/module plt → Common alias Basic Plot Syntax ……
x = [1, 2, 3, 4] y = [10, 20,……
(1,10) (2,20) (3,30) (4,40)…
Y 40 | * 30 | * 20 | * 10 | *……
Why Matplotlib?
Matplotlib useful for: Data visualization Data analysis Scientific computing Statistics Machine Learning resu……
Installing Matplotlib
Official installation can be done with pip, for example: python……
Matplotlib alias: plt…
import matplotlib.pyplot as p……
NumPy → np Pandas → pd Matplotlib pypl……
What is Pyplot?
pyplot என்பது Matplotlib-ல் plotting functions access செய்ய commonly used inte……
X-Axis and Y-Axis
Graph-க்கு பொதுவாக இரண்டு axe……
x = [1, 2, 3] y = [50, 70, 90……
days = [1, 2, 3, 4, 5] marks = [50, 60, 70, 80……
plt.plot()
plt.plot() primarily plots y vers……
plt.plot( [1, 2, 3], [10, 20,……
X and Y sequences normally need corresponding da……
Wrong: x = [1, 2, 3] y = [10, 20] plt.p……
Plot with Only Y Values
y = [10, 20, 30, 40] plt.plot(y) plt.show() If only Y dat……
x → 0 1 2 3 y →10 20 30 40…
Markers
Markers show individual data ……
plt.plot( x, y, marker="o" ) ……
x = [1, 2, 3, 4] y = [10, 20, 15, 30] plt.plo……
Common markers: o → Circle s ……
- → Star - → Plus…
x → X marker . → Point Matplotlib plot() accepts……
Line Style
plt.plot( x, y, linestyle="--……
- → Solid…
-- → Dashed -. → Dash-dot : → D……
Circle markers Dashed connect……
Line Width
plt.plot( x, y, linewidth=3 )……
Figure Title
Use: plt.title("Student Marks……
x = [1, 2, 3] y = [70, 80, 90] plt……
X-Axis Label
plt.xlabel("Days")…
Y-Axis Label
plt.ylabel("Marks")…
days = [1, 2, 3, 4] marks = [60, 70, 75, 90] plt.plot(da……
Title → Student Progress X-ax……
plt.title("Student Progress") Graph heading.……
TXY T → Title X → X label Y →……
Grid
Grid lines help read graph values. plt.grid……
x = [1, 2, 3, 4] y = [20, 30,……
Multiple Lines in One Graph
Student A: 60 70 80 Student B……
x = [1, 2, 3] a = [60, 70, 80] b = [50, 75, 90……
Legend
Legend identifies each plotte……
plt.plot( x, a, label="Arun" ……
days = [1, 2, 3] arun = [70, 80, 90] bala = [60, 75, 85] plt.plot( days, arun, label="Ar……
label= defines series name. l……
label → Name it legend → Show……
Line plot connects data points using lines. Useful fo……
plt.plot(x, y)…
months = [1, 2, 3, 4] sales = [100, 150, 140, 200] plt.plot( mont……
Bar chart categorical values compare செய்ய பயன்படுகிறது. O……
Arun → 90 Bala → 75 Kumar → 85 plt.bar(x, height) ……
students = [ "Arun", "Bala", "Kumar" ] marks = [ 90, 75, 85 ] plt.……
Marks 90 | █ 80 | █ █ 70 | █ ……
plt.bar( students, marks ) st……
Bar chart useful for: Category comparison Examples: ……
Horizontal Bar Chart
Use: plt.barh(x, values)…
plt.barh( students, marks ) B……
Scatter plot uses individual markers to show relationship/distribution betwe……
plt.scatter(x, y)…
hours = [1, 2, 3, 4, 5] marks = [45, 55, 65, 78, 90] plt.scatter( h……
Points: (1,45) (2,55) (3,65) (4,78) (5,90) No need t……
Pie chart ஒரு whole-ஐ slices/fractions ஆக represent செய்கிறது.……
plt.pie(values) With labels:…
subjects = [ "Python", "Java"……
plt.title("Course Selection")……
Total: 50 + 30 + 20 = 100 Pie……
Percentage in Pie Chart
Use: autopct="%1.1f%%"…
plt.pie( students, labels=subjects, autopct="%1……
Python 50.0% Java 30.0% C 20.……
Explode in Pie Chart
One slice highlight செய்ய: explode = [0.1, 0, 0] Then: plt.pie( students, la……
Histogram numerical data distribution-ஐ intervals or bins ஆக divide செய்து f……
plt.hist(data) Specify bins:…
marks = [ 45, 50, 52, 60, 65,……
plt.xlabel("Marks") plt.ylabel("F……
Suppose marks: 41-50 → 2 students 51-60 → 2 students 61-70……
bins means: How data range is divided into intervals/grou……
Figure
A Figure is the overall drawing/container that holds one or more plotting are……
plt.figure() plt.plot( [1, 2,……
Figure Size
figsize controls the figure dim……
plt.plot( [1, 2, 3], [10, 20,……
figsize = Figure Size…
Figure vs Axes
This is one of the most important Matplotlib concepts. Think: Figure ┌─────────────────────────┐ │ │ │ A……
Students often think: Axes = only X-axis + Y-axis That is incomplete. In ……
Object-Oriented Method
A very common modern pattern: fig, ax = plt.sub……
x = [1, 2, 3] y = [10, 20, 30] fig, ax = plt.subplots() a……
fig, ax = plt.subplots() Creates: fig → Figure ax → Axes ax.plot(x, y……
Pyplot Style vs Object-Oriented Style Pyplot: plt.plot(x, y) plt.title("Graph") Object-Oriented: fig, ax = pl……
Subplots
Subplots means: Multiple graphs inside one figure. ……
x = [1, 2, 3] y1 = [10, 20, 30] y2 = [30, 20, 10] fig, axes = plt.subplots(……
plt.subplots(1, 2) means: 1 r……
Figure ┌────────────┬────────────┐ │ Axe……
2 × 2 Subplots fig, axes = plt.subplots( 2, 2 ) Total: 2 ……
Saving a Graph
Use: plt.savefig("graph.png") Official savefig() saves the current figure to an image or v……
x = [1, 2, 3] y = [10, 20, 30] p……
Common save extensions include: .png .pdf .svg savefig() c……
DPI
DPI: Dots Per Inch Save:…
Higher DPI → More output pixe……
Axis Limits
Set X range: plt.xlim(0, 10) ……
plt.xlim( 0, 5 ) plt.ylim( 0,……
Tick Marks
Custom X ticks: plt.xticks( [1, 2, 3,……
NumPy with Matplotlib
NumPy and Matplotlib commonly……
plt.plot(x, y) plt.show()…
Pandas with Matplotlib
Pandas DataFrame values can b……
data = { "Name": [ "Arun", "B……
plt.bar( df["Name"], df["Mark……
Pandas DataFrame ↓ Select col……
NPM Flow NumPy ↓ Numbers Pand……
Important Plot Types
Matplotlib's official plot-type refer……
Which Graph Should I Use? Trend over time: Line Plot Compare categories: Ba……
Complete Basic Plot import matplotlib.pyplot as plt x = [1, 2, 3, 4] y = [60, 70, 80, 90] plt.p……
plt.plot(...) Creates plot. marker="o" Circle marker. label="Marks" Series label. plt.title(...) Graph ……
Wrong Import Wrong: import matplotlib pyplot as plt C……
Plt instead of plt Wrong: Plt.plot(……
Missing Comma in Lists Wrong: pl……
plt show Wrong: plt show() Co……
plt.show Without Call plt.show Thi……
List Object Is Not Callable Suppose student writes: plt.plot = [1, 2, 3] Now plt.plot function name has been ……
plt.newfig() Wrong: plt.newfig() There is no standard pyplot ……
plt.new figure() Wrong: plt.new figure() Pyth……
Different X and Y Length Wrong: x = [1, 2, 3] y = [10, 20] plt.plot(x, y) Bo……
Bar and Histogram Same என்று நினைப்பது Bar: plt.bar() Category comparison. Histogram: plt.hist() Numerica……
plot() and scatter() Same என்று நினைப்பது Line: plt.plot(x……
Save After Closing Safer order when both saving and displaying: plt.savefig("graph……
Matplotlib Master Memory P T X Y G L S P → Plot T → Title X → X label Y → Y label ……
Plot-Type Memory L B S P H L ……
Graph Selection Trend → Line Compare → B……
Matplotlib is a Python visualization libr……
Common import: import matplot……
Common alias: plt…
Line plot: plt.plot()…
Bar chart: plt.bar()…
Scatter plot: plt.scatter()…
Pie chart: plt.pie()…
Histogram: plt.hist()…
Graph display: plt.show()…
Graph title: plt.title()…
X-axis label: plt.xlabel()…
Y-axis label: plt.ylabel()…
Grid: plt.grid()…
Legend: plt.legend()…
New Figure: plt.figure()…
Subplots: plt.subplots()…
Save figure: plt.savefig()…
figsize controls Figure size.…
bins is an important histogra……
autopct can show percentages ……
Figure is the overall plottin……
Axes is the actual plotting a……
fig, ax = plt.subplots() crea……
What is Matplotlib? Answer Matplotlib is a Python library for creating visualiz……
What is pyplot? Answer pyplot is a Matplotlib plotting interface that p……
What does plt.plot() do? Answer plt.plo……
What does plt.show() do? Answer It requests di……
What is the difference between a Figure and Axes? Answer A Figure is the ……
What is the difference between bar chart and histogram? Answer A bar chart compares ……
What is the difference between line plot and scatter plot? Answer A line plot normally connects ……
What is a subplot? Answer A subplot is one plotting area withi……
How do you save a Matplotlib graph? Answer Use: plt.sav……
What is a histogram bin? Answer A bin represents an interval us……
Matplotlib is mainly used for:…
Which is the common import? A. import matplotlib as pd B. i……
Common pyplot alias is:…
Which function creates a comm……
Which displays the plot?…
Which creates a vertical bar ……
Which creates a scatter plot?…
Which creates a pie chart?…
Which creates a histogram?…
Which adds X-axis label?…
Which adds Y-axis label?…
Which adds graph title?…
Which displays legend informa……
Which displays grid lines?…
Which creates a new Figure?…
What is the correct command? A. plt show() B……
Which is best for categorical……
Which is best for numerical f……
Which is best to study relati……
What does bins commonly contr……
Which method saves a figure?…
What does this create? fig, a……
What does this mean? plt.subp……
Which graph commonly shows pa……
Which option can show percent……
Create a line plot: x = 1,2,3,4 y = 10,20,30,40 Answer: imp……
Add circle markers. plt.plot(……
Add title: plt.title( "My Fir……
Add labels: plt.xlabel( "X Va……
Add grid: plt.grid()…
Create Bar Chart: import matplotlib.pyplot as plt na……
Create Scatter Plot: x = [1, 2, 3,……
Create Pie Chart: values = [ 50, 30, 20 ] labels = ……
Create Histogram: marks = [ 40, 45, 50, 5……
Create two lines with legend. x = [1, 2, 3] a = [10, 20, 30] ……
Create a new Figure: plt.figu……
Save graph: plt.savefig( "myg……
Create Figure and Axes: fig, ax = pl……
Create 1 × 2 subplots. fig, a……
Choose the correct graph: Student marks by subject: Bar Chart Daily temperature tr……
Matplotlib is a Python visualization library. pyplot provides convenient plotting functions. Common alias is ……
Matplotlib → Visualization Import → import matplotlib.pyplot as plt Alias → plt Line → plt.plot() Bar → plt.b……