Matplotlib Summary
Matplotlib – ESSENTIALS
1️⃣ Import & Basic Workflow
Purpose Code
Import import [Link] as plt
Plot [Link](x, y)
Display [Link]()
2️⃣ Line Plot
Element Example
Simple line [Link](x, y)
Color color='r'
Line style linestyle='--'
Line width linewidth=2
Marker marker='o'
Full example [Link](x, y, color='r', linestyle='--', linewidth=2, marker='o')
3️⃣ Styles – Colors
Code Color
'r' Red
'g' Green
'b' Blue
'k' Black
'y' Yellow
'm' Magenta
4️⃣ Styles – Line Types
Matplotlib Summary 1
Code Style
'-' Solid
'--' Dashed
':' Dotted
'-.' Dash-dot
5️⃣ Styles – Markers
Code Shape
'o' Circle
'*' Star
'x' Cross
's' Square
'^' Triangle
6️⃣ Format String ( fmt )
Format Meaning
'o--r' marker + line + color
7️⃣ Titles, Labels, Legend, Grid
Element Code
Title [Link]("Title")
X label [Link]("X")
Y label [Link]("Y")
Legend [Link]()
Grid [Link](True)
8️⃣ Axes & Ticks
Action Code
X ticks [Link]([1,2,3])
Matplotlib Summary 2
Action Code
Y ticks [Link]([0,5,10])
X limits [Link](0,10)
Y limits [Link](0,50)
9️⃣ Figure Size & Transparency
Action Code
Figure size [Link](figsize=(6,4))
Transparency alpha=0.7
🔟 Default X Values
Case Result
[Link](y) x = [0,1,2,...]
1️⃣1️⃣ Scatter Plot
Action Code
Simple scatter [Link](x, y)
Size s=100
Color c='g'
Transparency alpha=0.5
1️⃣2️⃣ Bar Chart
Type Code
Vertical [Link](x, y)
Horizontal [Link](x, y)
1️⃣3️⃣ Pie Chart
Matplotlib Summary 3
Action Code
Pie chart [Link](values, labels=labels, autopct='%1.1f%%')
1️⃣4️⃣ Subplots
Action Code
Create [Link](1,2,1)
Display [Link]()
1️⃣5️⃣ Save a Figure
Action Code
Save [Link]("[Link]")
1️⃣6️⃣ With Pandas
Action Code
Plot from DataFrame df['col'].plot(kind='bar')
🔴 IMPORTANT FOR THE EXAM
Must Know Why
[Link]() Core function
title / xlabel / ylabel Clarity
legend() Interpretation
grid(True) Readability
subplot() Comparison
figsize Presentation
xlim / ylim Control
plot vs scatter vs bar Very common question
fmt Trick question
Matplotlib Summary 4
ASTUCE D’EXAM
Si une question demande :
“Créer un graphique clair et lisible”
👉 toujours écrire :
[Link](...)
[Link](...)
[Link](...)
[Link](True)
[Link]()
Purpose /
# Concept Example
Explanation
Import
1️⃣ Import Matplotlib import [Link] as plt
plotting module
2️⃣ Basic workflow
Create plot then
display it
[Link](x,y)[Link]()
3️⃣ Line plot
Draw a line
graph
[Link](x, y)
Customize
4️⃣ Line style color, line,
[Link](x,y,color='r',linestyle='--
',marker='o')
marker
5️⃣ Colors
Change plot
color
'r','g','b','k','y','m'
6️⃣ Line styles
Change line
appearance
'-' '--' ':' '-.'
7️⃣ Markers Point shapes 'o' '*' 'x' 's' '^'
8️⃣ Format string
( fmt )
marker + line +
color
[Link](x,y,'o--r')
9️⃣ Title
Add title to
graph
[Link]("My Graph")
🔟 X label Label X axis [Link]("X")
Matplotlib Summary 5
Purpose /
# Concept Example
Explanation
1️⃣1️⃣ Y label Label Y axis [Link]("Y")
1️⃣2️⃣ Legend
Explain plotted
curves
[Link]()
1️⃣3️⃣ Grid Show grid [Link](True)
1️⃣4️⃣ X ticks
Custom X-axis
values
[Link]([1,2,3])
1️⃣5️⃣ Y ticks
Custom Y-axis
values
[Link]([0,5,10])
1️⃣6️⃣ Default X
values
Auto-generate X [Link]([2,4,6]) → x=[0,1,2]
1️⃣7️⃣ Scatter plot Display points [Link](x,y)
1️⃣8️⃣ Scatter options
Size, color,
transparency
[Link](x,y,s=100,c='g',alpha=0.5)
1️⃣9️⃣ Bar chart Vertical bars [Link](cat, val)
2️⃣0️⃣ Horizontal bar Horizontal bars [Link](cat, val)
2️⃣1️⃣ Pie chart
Percentage
visualization
[Link](v, labels=l,
autopct='%1.1f%%')
2️⃣2️⃣ Subplots
Multiple plots in
one figure
[Link](1,2,1)
2️⃣3️⃣ Save figure
Export plot as
image
[Link]("[Link]")
2️⃣4️⃣ Pandas +
Matplotlib
Plot directly
from DataFrame
df['col'].plot(kind='bar')
Matplotlib Summary 6