■ Matplotlib Cheatsheet (with Explanations)
1. Import
import [Link] as plt
2. Basic Plot
[Link]([1,2,3,4], [10,20,25,30]) # Line plot (x,y)
[Link]() # Display the plot
3. Plot Types
[Link](x,y) # Line plot
[Link](x,y) # Scatter plot
[Link](x,heights) # Bar chart (vertical)
[Link](y,widths) # Horizontal bar chart
[Link](data, bins=10) # Histogram
[Link](sizes, labels=labels) # Pie chart
4. Titles, Labels, Legends
[Link]("My Plot") # Title
[Link]("X-axis") # X label
[Link]("Y-axis") # Y label
[Link](["Series1","Series2"]) # Legend
5. Customizing Line & Markers
[Link](x,y, color='red', linestyle='--', marker='o')
# color: 'red', 'g', '#FF0000'
# linestyle: '-', '--', '-.', ':'
# marker: 'o', 's', 'd', '^'
6. Subplots (Multiple plots in one figure)
[Link](2,1,1) # 2 rows, 1 col, 1st plot
[Link](x,y1)
[Link](2,1,2) # 2 rows, 1 col, 2nd plot
[Link](x,y2)
7. Figure & Axes (Object-Oriented)
fig, ax = [Link]() # Create figure and axes
[Link](x,y) # Plot on this axes
ax.set_title("Title") # Set title
ax.set_xlabel("X label") # X label
ax.set_ylabel("Y label") # Y label
8. Multiple Lines
[Link](x, y1, label="Line 1")
[Link](x, y2, label="Line 2")
[Link]()
9. Style & Grid
[Link]('ggplot') # Predefined style (ggplot, seaborn, etc.)
[Link](True) # Show grid
10. Saving Plots
[Link]("[Link]") # Save as PNG
[Link]("[Link]") # Save as PDF
[Link]("[Link]", dpi=300) # Save with resolution
11. Common Use Cases
- Line plots → Trends over time
- Scatter plots → Relationship between two variables
- Bar charts → Compare categories
- Histograms → Data distribution
- Pie charts → Proportions
- Subplots → Compare multiple plots together